Correct TypeScript from WorkerEntrypoint Binding

If I have this service below
export default class Users extends WorkerEntrypoint<Env> {
async fetch() {
return new Response(null, { status: 404 });
}

async list() {
const adapter = new PrismaD1(this.env.DB);
const prisma = new PrismaClient({ adapter });

try {
const users = await prisma.user.findMany();
const result = JSON.stringify(users);
return new Response(result);
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
return Response.json({ e }, { status: 400 });
}
return Response.json({ e }, { status: 500 });
}
}
export default class Users extends WorkerEntrypoint<Env> {
async fetch() {
return new Response(null, { status: 404 });
}

async list() {
const adapter = new PrismaD1(this.env.DB);
const prisma = new PrismaClient({ adapter });

try {
const users = await prisma.user.findMany();
const result = JSON.stringify(users);
return new Response(result);
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
return Response.json({ e }, { status: 400 });
}
return Response.json({ e }, { status: 500 });
}
}
wrangler.toml
name = "users"
main = "src/index.ts"
compatibility_date = "2025-01-09"
wrangler.toml
name = "users"
main = "src/index.ts"
compatibility_date = "2025-01-09"
When I consume this into another service provider it has in its toml
wrangler.toml
[[services]]
binding = "USERS"
service = "users"
entrypoint = "Users"
wrangler.toml
[[services]]
binding = "USERS"
service = "users"
entrypoint = "Users"
When I run wrangler types it generaties this type decleration file
// Generated by Wrangler by running `wrangler types`

interface Env {
USERS: Fetcher;
}
// Generated by Wrangler by running `wrangler types`

interface Env {
USERS: Fetcher;
}
However when I try to use this service it only shows two methods which are the reserved types connect and fetch
No description
1 Reply
DaniFoldi
DaniFoldi3d ago
There's a separate type for RPC services, Service<Users> in this case, if you import type Users from './other.ts' The way I usually have them would be USERS: Service<import('other-service').default> as inline type imports

Did you find this page helpful?