DurableObjectNamespace losing its type?

I have a worker-configuration.d.ts that looks like this:
interface Env {
CHATSTORE: DurableObjectNamespace<import("./build/index").ChatStore>;
}
interface Env {
CHATSTORE: DurableObjectNamespace<import("./build/index").ChatStore>;
}
I also have "types": ["@remix-run/cloudflare", "@cloudflare/workers-types"], in my tsconfig.json so that Env is available everywhere in my app. However, Env["CHATSTORE"] shows up as DurableObjectNamespace<any> everywhere, instead of DurableObjectNamespace<ChatStore>. How do I get that type to not devolve to any?
4 Replies
Hello, I’m Allie!
Is worker-configuration in your src?
zsmooth
zsmoothOP2mo ago
It's in my project root. (I'm in a remix app). The ./build/index path is correct relative to the file if i manually change it to:
CHATSTORE: DurableObjectNamespace<
import("./app/durable_objects/chat_store").ChatStore
>;
CHATSTORE: DurableObjectNamespace<
import("./app/durable_objects/chat_store").ChatStore
>;
then it works, but this file is automatically generated, and the next time i run wrangler types it would get blown away also, this is include from my tsconfig:
"include": [
"worker-configuration.d.ts",
"remix.env.d.ts",
"env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"include": [
"worker-configuration.d.ts",
"remix.env.d.ts",
"env.d.ts",
"**/*.ts",
"**/*.tsx"
],
for now, i just added a env.d.ts file, and put this in it:
declare global {
interface Env {
CHATSTORE: DurableObjectNamespace<
import("./app/durable_objects/chat_store").ChatStore
>;
}
}
declare global {
interface Env {
CHATSTORE: DurableObjectNamespace<
import("./app/durable_objects/chat_store").ChatStore
>;
}
}
i think since it comes after the worker-configuration in my tsconfig, it loads after and augments Env with the correct type never mind, still doesn't work
Hello, I’m Allie!
Sorry I meant the src of your tsconfig
zsmooth
zsmoothOP2mo ago
{
"include": [
"worker-configuration.d.ts",
"remix.env.d.ts",
"env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["@remix-run/cloudflare", "@cloudflare/workers-types"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
{
"include": [
"worker-configuration.d.ts",
"remix.env.d.ts",
"env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["@remix-run/cloudflare", "@cloudflare/workers-types"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
Want results from more Discord servers?
Add your server