Skip to content

Commit f4cfded

Browse files
committed
fix: wrangler types decouple env-interface from namespace
1 parent b17797c commit f4cfded

File tree

4 files changed

+310
-279
lines changed

4 files changed

+310
-279
lines changed

.changeset/fine-years-create.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Wrangler types decouple env-interface from namespace.
6+
7+
The `wrangler types` command now adds a `BaseEnv` interface which is then extended by `Cloudflare.Env` and the `--env-interface`

packages/wrangler/e2e/types.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("types", () => {
4949
await helper.seed(seed);
5050
const output = await helper.run(`wrangler types`);
5151
expect(output.stdout).toContain("Generating project types...");
52-
expect(output.stdout).toContain("interface Env {");
52+
expect(output.stdout).toContain("interface Env extends BaseEnv {");
5353
expect(output.stdout).toContain("Generating runtime types...");
5454
expect(output.stdout).toContain("Runtime types generated.");
5555
expect(output.stdout).toContain(
@@ -74,16 +74,17 @@ describe("types", () => {
7474
);
7575
expect(file).toMatchInlineSnapshot(`
7676
"/* eslint-disable */
77-
// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: 5c82572f95137bbfb775d02fdf441070)
77+
// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: fbdd9c78deb72b14fc06ea86f1940c82)
78+
interface BaseEnv {
79+
MY_VAR: "my-var-value";
80+
}
7881
declare namespace Cloudflare {
7982
interface GlobalProps {
8083
mainModule: typeof import("./src/index");
8184
}
82-
interface Env {
83-
MY_VAR: "my-var-value";
84-
}
85+
interface Env extends BaseEnv {}
8586
}
86-
interface Env extends Cloudflare.Env {}
87+
interface Env extends BaseEnv {}
8788
"
8889
`);
8990
});
@@ -99,7 +100,7 @@ describe("types", () => {
99100
).split("\n");
100101

101102
expect(lines[1]).toMatchInlineSnapshot(
102-
`"// Generated by Wrangler by running \`wrangler types ./types.d.ts\` (hash: 5c82572f95137bbfb775d02fdf441070)"`
103+
`"// Generated by Wrangler by running \`wrangler types ./types.d.ts\` (hash: fbdd9c78deb72b14fc06ea86f1940c82)"`
103104
);
104105
expect(lines[2]).match(
105106
/\/\/ Runtime types generated with workerd@1\.\d{8}\.\d \d{4}-\d{2}-\d{2} ([a-z_]+,?)*/
@@ -126,7 +127,7 @@ describe("types", () => {
126127
).split("\n");
127128

128129
expect(lines[1]).toMatchInlineSnapshot(
129-
`"// Generated by Wrangler by running \`wrangler types -c wranglerA.toml --env-interface MyCloudflareEnv ./cflare-env.d.ts\` (hash: e981fccb455c04c58ced00f3442b83ac)"`
130+
`"// Generated by Wrangler by running \`wrangler types -c wranglerA.toml --env-interface MyCloudflareEnv ./cflare-env.d.ts\` (hash: ae7e85ef5d4b4e21c6e897e59e7c34fc)"`
130131
);
131132
expect(lines[2]).match(
132133
/\/\/ Runtime types generated with workerd@1\.\d{8}\.\d \d{4}-\d{2}-\d{2} ([a-z_]+,?)*/
@@ -158,7 +159,7 @@ describe("types", () => {
158159
const file2 = readFileSync(typesPath, "utf8");
159160

160161
// regenerates env types
161-
expect(file2).toContain("interface Env {");
162+
expect(file2).toContain("interface Env extends BaseEnv {");
162163
// uses cached runtime types
163164
expect(file2).toContain("// Begin runtime types");
164165
expect(file2).toContain("FAKE RUNTIME");
@@ -180,17 +181,18 @@ describe("types", () => {
180181
);
181182
expect(file).toMatchInlineSnapshot(`
182183
"/* eslint-disable */
183-
// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: 1457dc49fa39d3fb92583c9c66b2dbe5)
184+
// Generated by Wrangler by running \`wrangler types --include-runtime=false\` (hash: 33f3189d3ee367953f0e81f02a1f1800)
185+
interface BaseEnv {
186+
MY_VAR: "my-var-value";
187+
MY_SECRET_VAR: string;
188+
}
184189
declare namespace Cloudflare {
185190
interface GlobalProps {
186191
mainModule: typeof import("./src/index");
187192
}
188-
interface Env {
189-
MY_VAR: "my-var-value";
190-
MY_SECRET_VAR: string;
191-
}
193+
interface Env extends BaseEnv {}
192194
}
193-
interface Env extends Cloudflare.Env {}
195+
interface Env extends BaseEnv {}
194196
"
195197
`);
196198
});

0 commit comments

Comments
 (0)