RPC method types debugging

yeah nvm actually false alarm
19 Replies
darkpool
darkpoolOP3d ago
@Kiwi there has to be a tsconfig that will tell tsc to link the packages. I tried adding the other d.ts files in include but didnt work either:
"include": [
"worker-configuration.d.ts",
"src/**/*.ts",
"extended-env.d.ts",
"../dispatch/worker-configuration.d.ts",
"../config/worker-configuration.d.ts"
]
"include": [
"worker-configuration.d.ts",
"src/**/*.ts",
"extended-env.d.ts",
"../dispatch/worker-configuration.d.ts",
"../config/worker-configuration.d.ts"
]
Kiwi
Kiwi3d ago
Yeah that is effectively what I am already doing
darkpool
darkpoolOP3d ago
so your method passes tsc?
Kiwi
Kiwi3d ago
"types": ["./reset.d.ts", "./worker-configuration.d.ts", "./cloudflare-service-bindings.d.ts", "node"],
interface CloudflareServiceBindings {
USERS_SERVICE: import('./src/users/UsersService').UsersService;
}

interface Env extends CloudflareServiceBindings {}
interface CloudflareServiceBindings {
USERS_SERVICE: import('./src/users/UsersService').UsersService;
}

interface Env extends CloudflareServiceBindings {}
Something like that And for clarity, the interface Env extends CloudflareServiceBindings {} opens the Env interface and extends it
darkpool
darkpoolOP3d ago
are you using the new typegen with wrangler 4? still having trouble with your method. do you mind giving it a quick glance to see if im doing anything dumb?
interface CloudflareServiceBindings {
DISPATCH_SERVICE: import("../../dispatch/src/index").default;
CONFIG_SERVICE: import("../../config/src/index").default;
}

interface Env extends CloudflareServiceBindings {}

export default class DBService extends WorkerEntrypoint {
env: Env;
interface CloudflareServiceBindings {
DISPATCH_SERVICE: import("../../dispatch/src/index").default;
CONFIG_SERVICE: import("../../config/src/index").default;
}

interface Env extends CloudflareServiceBindings {}

export default class DBService extends WorkerEntrypoint {
env: Env;
{
"extends": "@morpheus/typescript-config/worker.json",
"exclude": ["test"],
"compilerOptions": {
"types": ["./worker-configuration.d.ts", "./extended-env.d.ts"]
},
"include": ["worker-configuration.d.ts", "src/**/*.ts", "extended-env.d.ts"]
}
{
"extends": "@morpheus/typescript-config/worker.json",
"exclude": ["test"],
"compilerOptions": {
"types": ["./worker-configuration.d.ts", "./extended-env.d.ts"]
},
"include": ["worker-configuration.d.ts", "src/**/*.ts", "extended-env.d.ts"]
}
when I run tsc --noEmit I get errors like:
../config/src/index.ts:40:18 - error TS2339: Property 'CONFIG_STORE' does not exist on type 'Env'.

40 const id = env.CONFIG_STORE.idFromName("default");
../config/src/index.ts:40:18 - error TS2339: Property 'CONFIG_STORE' does not exist on type 'Env'.

40 const id = env.CONFIG_STORE.idFromName("default");
Kiwi
Kiwi3d ago
Does your type list include the file which has CloudflareServiceBindings?
darkpool
darkpoolOP3d ago
yes thats ./extended-env.d.ts
Kiwi
Kiwi3d ago
Otherwise looks fine Maybe WorkerEntrypoint takes the generic? WorkerEntrypoint<Env>?
darkpool
darkpoolOP3d ago
what are you using for monorepo management? im on turborepo
Kiwi
Kiwi3d ago
Oh, CONFIG_STORE isn't CONFIG_SERVICE I'm not turborepo, but a bun workspaces repo but same flavour of problem
darkpool
darkpoolOP3d ago
CONFIG_SERVICE is the worker and CONFIG_STORE is a DO
Kiwi
Kiwi3d ago
And that is already defined in Env? Oh I just reminded byself that I do this in my WorkerEntrypoint WorkerEntrypoint<Env & CloudflareServiceBindings> which should be redundant
darkpool
darkpoolOP3d ago
tried this just now but same issue when i log my env its still showing │ db env { │ ENVIRONMENT: 'dev', │ SPANNER_DATABASE_ID: 'db-1', │ DISPATCH_SERVICE: Fetcher {}, │ CONFIG_SERVICE: Fetcher {} │ } the fetcher???
Kiwi
Kiwi3d ago
so I think my setup is not 100% since I am doing WorkerEntrypoint<Env & CloudflareServiceBindings> in places Env should already be Env & CloudflareServiceBindings so there is an obvious setup issue in my repo But otherwise doing the union does give you the result you are after, but it's more verbose/explicit and should have already been set up by the compiler config types array
darkpool
darkpoolOP3d ago
so just like?
interface CloudflareServiceBindings {
DISPATCH_SERVICE: import("../../dispatch/src/index.js").default;
CONFIG_SERVICE: import("../../config/src/index.js").default;
}

interface Env extends CloudflareServiceBindings {}

export default class DBService extends WorkerEntrypoint<
Env & CloudflareServiceBindings
> {
env: Env & CloudflareServiceBindings;
interface CloudflareServiceBindings {
DISPATCH_SERVICE: import("../../dispatch/src/index.js").default;
CONFIG_SERVICE: import("../../config/src/index.js").default;
}

interface Env extends CloudflareServiceBindings {}

export default class DBService extends WorkerEntrypoint<
Env & CloudflareServiceBindings
> {
env: Env & CloudflareServiceBindings;
? its still logging both services as Fetcher {} so confused lol
Kiwi
Kiwi3d ago
Yes, I think that is right. Your logs are run time right The Fetcher instance is what is created at runtime, with the RPC stuff done via some proxy indirection, so your RPC methods aren't going to be visible then at least thats my understanding
darkpool
darkpoolOP3d ago
ok that makes sense. prob some weird obscure tsconfig I have that your for your time sorry for all the questions lol one more - do you have a root tsconfig? or is everyrhing package/apps dependent?
Kiwi
Kiwi3d ago
I have one per package right now, but I think a root one would be doable
darkpool
darkpoolOP3d ago
ok same just checking if that might be the difference. btw meant to say thank you for your time haha not 'that your for'

Did you find this page helpful?