Skip to content

Commit 56dd36f

Browse files
committed
fixup! test command
1 parent 0726b85 commit 56dd36f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fixtures/dev-registry/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"check:types": "tsc --build",
77
"test": "vitest",
88
"test:ci": "vitest run",
9-
"types": "wrangler types -c ./wrangler.module-worker.jsonc -c ./wrangler.worker-entrypoint-a.jsonc",
109
"vite": "vite dev",
1110
"wrangler": "wrangler dev"
1211
},

packages/wrangler/src/type-generation/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ export async function generateEnvTypes(
470470
let typeName: string;
471471

472472
if (importPath && exportExists) {
473-
typeName = `Service<(typeof import("${importPath}"))['${service.entrypoint ?? "default"}']>`;
473+
typeName = `Service<MaybeWorkerEntrypoint<typeof import("${importPath}").${service.entrypoint ?? "default"}>>`;
474474
} else if (service.entrypoint) {
475475
typeName = `Service /* entrypoint ${service.entrypoint} from ${service.service} */`;
476476
} else {
@@ -709,6 +709,8 @@ function generateTypeStrings(
709709
let baseContent = "";
710710
let processEnv = "";
711711

712+
const MaybeWorkerEntrypointType = `\ttype MaybeWorkerEntrypoint<T> = T extends new (...args: any[]) => infer EntrypointClass\n\t\t? EntrypointClass extends Rpc.WorkerEntrypointBranded ? EntrypointClass : undefined\n\t\t: undefined;`;
713+
712714
if (formatType === "modules") {
713715
if (
714716
isProcessEnvPopulated(compatibilityDate, compatibilityFlags) &&
@@ -717,7 +719,7 @@ function generateTypeStrings(
717719
// StringifyValues ensures that json vars are correctly types as strings, not objects on process.env
718720
processEnv = `\ntype StringifyValues<EnvType extends Record<string, unknown>> = {\n\t[Binding in keyof EnvType]: EnvType[Binding] extends string ? EnvType[Binding] : string;\n};\ndeclare namespace NodeJS {\n\tinterface ProcessEnv extends StringifyValues<Pick<Cloudflare.Env, ${stringKeys.map((k) => `"${k}"`).join(" | ")}>> {}\n}`;
719721
}
720-
baseContent = `declare namespace Cloudflare {\n\tinterface Env {${envTypeStructure.map((value) => `\n\t\t${value}`).join("")}\n\t}\n}\ninterface ${envInterface} extends Cloudflare.Env {}${processEnv}`;
722+
baseContent = `declare namespace Cloudflare {\n${MaybeWorkerEntrypointType}\n\n\tinterface Env {${envTypeStructure.map((value) => `\n\t\t${value}`).join("")}\n\t}\n}\ninterface ${envInterface} extends Cloudflare.Env {}${processEnv}`;
721723
} else {
722724
baseContent = `export {};\ndeclare global {\n${envTypeStructure.map((value) => `\tconst ${value}`).join("\n")}\n}`;
723725
}

0 commit comments

Comments
 (0)