Typescript types for fetch in module syntax

I'm migrating a worker to module syntax in a typescript project. What are the types of request and context? I know env is my own interface.
export default {
fetch(request: ???, env: MyEnv, context: ???) {
return new Response('Hello');
},
};
export default {
fetch(request: ???, env: MyEnv, context: ???) {
return new Response('Hello');
},
};
`
2 Replies
Tin Cap
Tin CapOP2y ago
Request - Web APIs | MDN
The Request interface of the Fetch API represents a resource request.
Tin Cap
Tin CapOP2y ago
I can't find ExecutionContext That's what I thought, maybe it's a misconfiguration. I have
"@cloudflare/workers-types": "^4.20230518.0",
"@cloudflare/workers-types": "^4.20230518.0",
yeah, this project is a few years old, so this might be a little funky
{
"compilerOptions": {
"outDir": "./dist",
"module": "commonjs",
"target": "esnext",
"lib": ["esnext", "webworker"],
"alwaysStrict": true,
"strict": true,
"preserveConstEnums": true,
"moduleResolution": "node",
"sourceMap": true,
"esModuleInterop": true,
"types": ["@cloudflare/workers-types", "jest"]
},
"include": [
"./src/*.ts",
"./test/*.ts",
"./src/**/*.ts",
"./test/**/*.ts",
"./node_modules/@cloudflare/workers-types/index.d.ts"
],
"exclude": ["node_modules/", "dist/"]
}
{
"compilerOptions": {
"outDir": "./dist",
"module": "commonjs",
"target": "esnext",
"lib": ["esnext", "webworker"],
"alwaysStrict": true,
"strict": true,
"preserveConstEnums": true,
"moduleResolution": "node",
"sourceMap": true,
"esModuleInterop": true,
"types": ["@cloudflare/workers-types", "jest"]
},
"include": [
"./src/*.ts",
"./test/*.ts",
"./src/**/*.ts",
"./test/**/*.ts",
"./node_modules/@cloudflare/workers-types/index.d.ts"
],
"exclude": ["node_modules/", "dist/"]
}
I think this all came from the old worker starer template , possibly plus jest good idea - I can copy stuff over from that I actually have a recently created project I can look at. And yeah I'm noticing the tsconfig is very different I'll start with that. Thanks!
Want results from more Discord servers?
Add your server