Remote Procedure Call Methods and TSC #10429
Unanswered
mgandolfi7
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I know this is not really in Turborepo's purview but I am wondering if anyone can give me some help on resolving RPC methods.
I have a microservice architecture with several cloudflare workers communicating over RPC. At this time, wrangler (Cloudflare CLI) does not generate types for RPC methods. There is a workaround which helps with IDE inference but tsc will still try and check types outside of the specified directory.
Example
Let's say I have 2 cloudflare workers in the /apps directory.
Worker 1 can expose an add method:
Worker 2 can call it like a regular function even though it executes on Worker 1:
Problem is I want to have type inference without manually typing params and responses. There is a current workaround to extend the Cloudflare Env object like this:
Then in Worker 2's index, we can add the new ExtendedEnv interface:
This works for my IDE but I cannot get it working with the TS compiler. If I run
tsc --noEmitin Worker 2, I will get something like:Note: EXAMPLE_VAR exists on Worker 1 but not Worker 2 (this should be checked on Worker 1 and not worker 2).
Worker 2 tsconfig.json
{ "extends": "@repo/typescript-config/worker.json", "compilerOptions": { "outDir": "dist", "types": ["./extended-env.d.ts"] }, "include": ["worker-configuration.d.ts", "src", "extended-env.d.ts"], "exclude": ["test", "node_modules", "../worker-1/**"] }Base json.config:
{ "$schema": "https://json.schemastore.org/tsconfig", "extends": "./base.json", "display": "Worker", "compilerOptions": { "target": "ESNext", "lib": ["ESNext"], "module": "ESNext", "moduleResolution": "Bundler", "resolveJsonModule": true, "allowJs": true, "checkJs": false, "noEmit": true, "isolatedModules": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "strict": true, "skipLibCheck": true } }Additional information
Others in the discussion seemed to get it working but I had no luck. Also important to note that I do not have a root tsconfig.
Beta Was this translation helpful? Give feedback.
All reactions