You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently encountered a type mismatch issue while writing test code for Cloudflare Worker's DurableObject by @cloudflare/vitest-pool-worker. The problem arises due to the fetch method being undefined, following the example provided in honojs/examples for creating a DurableObject.
Type 'MatchmakingDurableObject' does not satisfy the constraint 'DurableObject'.
Types of property 'fetch' are incompatible.
Type '((request: Request<unknown, CfProperties<unknown>>) => Response | Promise<Response>) | undefined' is not assignable to type '(request: Request<unknown, CfProperties<unknown>>) => Response | Promise<Response>'.
Type 'undefined' is not assignable to type '(request: Request<unknown, CfProperties<unknown>>) => Response | Promise<Response>'.ts(2344)
Notes
This commit of the example is just 1 week ago, so I know this is the new error. honojs/examples@9b7acf1
Temporarily I just define the fetch method on the DurableObject for the test, strangely.
The text was updated successfully, but these errors were encountered:
So this looks like the fetch function is potentially returning undefined? It's not clear to me if this is a problem with vitest-pool-workers types or workerd DO types. Adding to the backlog to investigate further.
I am saying that there are DurableObject base class and DurableObject interface in @cloudflare/workers-types, right?
So we are expecting DurableObject base class is subject to DurableObject interface, so do vitest-pool-worker.
(With my understanding, class in typescript auto-generates its interface.)
But actually, DurableObject base class has a fetch method optionally, however, not optionally in DurableObject interface.
Sorry for the delay in following up on this! Are you still seeing the types issue with the latest versions of wrangler, vitest-pool-workers, and workers-types? If so, could you share a repo that reproduces the issue?
I tried reproducing it myself but couldn't see the issue you described. It's possible that it has been resolved in a newer version 👍🏼
Abstract
I recently encountered a type mismatch issue while writing test code for Cloudflare Worker's DurableObject by
@cloudflare/vitest-pool-worker
. The problem arises due to the fetch method being undefined, following the example provided in honojs/examples for creating a DurableObject.Packages
Codes
src/Matchmaking.ts
test/Matchmaking.spec.ts
tsconfig.json
test/tsconfig.json
Error log on vscode
Notes
This commit of the example is just 1 week ago, so I know this is the new error.
honojs/examples@9b7acf1
Temporarily I just define the fetch method on the DurableObject for the test, strangely.
The text was updated successfully, but these errors were encountered: