cloudflare / cloudflare/workerd

Challenges and Solutions for Using Types in Turborepo with Service Bindings

Open
#3,113 11 comments 0 reactions 1 assignee Claimed by @workers-devprod View on GitHub
types
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

I am using Cloudflare Workers with tRPC and Turborepo. I wrote a service with Workers and created an API using Service Bindings.

```
// @package/cfw-services
import { WorkerEntrypoint } from 'cloudflare:workers';
export class ServiceWorker extends WorkerEntrypoint {
// Currently, entrypoints without a named handler are not supported
async fetch(request: Request) {
return new Response(null, { status: 404 });
}
}
```

```
// api env
import type { ServiceWorker } from '@packages/cfw-services';
export interface Env {
SERVICES: Service;
}

```
My issue is that when compiling the tRPC client, it references 'cloudflare:workers', which is defined in @cloudflare/workers-types but is not an exported module. My solution is, in the project where the tRPC client adding

```
"compilerOptions": {
"types": [
"@cloudflare/workers-types"
]
}
```

in the `tsconfig.json`.

This temporarily solves the issue, but in the future, any other app that needs to use the tRPC API will also need to add a reference to @cloudflare/workers-types in their tsconfig. So I’m considering whether it would be better to directly add an export for types like WorkerEntrypoint in the 'cloudflare:workers' module.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.