cloudflare / cloudflare/actors

DurableObjectStub obscures the type of sql method

Open
#22 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
422
Forks
28
PR merge metrics
No merged PRs in 30d

Description

If you do something like this

```ts
const actor = MyActor.get("test");
actor.sql<{ num: number }>`select 123 as num`
```

You will get an `Expected 0 type arguments, but got 1.` ts error, this is because the DurableObjectStub type is obscuring the sql type with the default one (SqlStorage)

I managed to hack a fix for it in my code with
```ts
export type ActorDurableObjectStub = Actor> =
DurableObjectStub & {
sql: typeof Actor.prototype.sql;
};
```

which is probably not great, but worked for me, there's probably a better way to wrap the stub type

a bigger problem is that, while you could wrap the type resulting from `getActor`, it will still be a problem if instantiating through `env.BINDING.get` which returns a DurableObjectStub

maybe a better fix would be to look into the root cause

Contributor guide

Open the contributing guide

Research direction

Trace the type returned by getActor and env.BINDING.get, comparing DurableObjectStub with Actor.prototype.sql; start at the DurableObjectStub typing and the sql declaration shown in the issue. Confirm done when generic type arguments are accepted through both access paths without obscuring the sql signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
sqlite, typescript
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.