Skip to content

Commit 2815fdc

Browse files
fixup! add loose-vars option to wrangler types
rename `loose-vars` to `strict-vars`
1 parent bed1a3a commit 2815fdc

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

.changeset/unlucky-timers-sort.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"wrangler": minor
33
---
44

5-
add `loose-vars` option to `wrangler types`
5+
add `strict-vars` option to `wrangler types`
66

7-
add a new `--loose-vars` option to `wrangler types` that developers can use to get more
8-
loose types for their variables instead of literal and union types
7+
add a new `--strict-vars` option to `wrangler types` that developers can use to enable/disable
8+
more strict/literal types for their variables
99

10-
these more loose types can be useful when developers change often their `vars` values,
10+
opting out of strict variables can be useful when developers change often their `vars` values,
1111
even more so when multiple environments are involved
1212

1313
## Example
@@ -33,7 +33,7 @@ interface Env {
3333
}
3434
```
3535

36-
while `wrangler types --loose-vars` would instead generate:
36+
while `wrangler types --strict-vars=false` would instead generate:
3737

3838
```
3939
interface Env {

packages/wrangler/src/__tests__/type-generation.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ describe("generateTypes()", () => {
602602
`);
603603
});
604604

605-
it("should respect the loose-vars option", async () => {
605+
it("should allow opting out of strict-vars", async () => {
606606
fs.writeFileSync(
607607
"./wrangler.toml",
608608
TOML.stringify({
@@ -616,7 +616,7 @@ describe("generateTypes()", () => {
616616
"utf-8"
617617
);
618618

619-
await runWrangler("types --loose-vars");
619+
await runWrangler("types --strict-vars=false");
620620

621621
expect(std.out).toMatchInlineSnapshot(`
622622
"Generating project types...
@@ -710,8 +710,8 @@ describe("generateTypes()", () => {
710710
`);
711711
});
712712

713-
it("should produce loose types for variables (with --loose-vars)", async () => {
714-
await runWrangler("types --loose-vars=true");
713+
it("should produce non-strict types for variables (with --strict-vars=false)", async () => {
714+
await runWrangler("types --strict-vars=false");
715715

716716
expect(std.out).toMatchInlineSnapshot(`
717717
"Generating project types...

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ export function typesOptions(yargs: CommonYargsArgv) {
3939
describe: "The path of the generated runtime types file",
4040
demandOption: false,
4141
})
42-
.option("loose-vars", {
42+
.option("strict-vars", {
4343
type: "boolean",
44-
default: false,
45-
describe:
46-
'Generate "loose"/generic types instead of literal and union types for variables',
44+
default: true,
45+
describe: "Generate literal and union types for variables",
4746
});
4847
}
4948

@@ -154,7 +153,7 @@ export async function typesHandler(
154153
config,
155154
envInterface,
156155
outputPath,
157-
args.looseVars
156+
args.strictVars
158157
);
159158
}
160159

@@ -253,7 +252,7 @@ async function generateTypes(
253252
config: Config,
254253
envInterface: string,
255254
outputPath: string,
256-
looseVars: boolean
255+
strictVars: boolean
257256
) {
258257
const configContainsEntrypoint =
259258
config.main !== undefined || !!config.site?.["entry-point"];
@@ -304,7 +303,7 @@ async function generateTypes(
304303
varInfo
305304
.map(({ value }) => value)
306305
.map((varValue) => {
307-
if (looseVars) {
306+
if (!strictVars) {
308307
if (Array.isArray(varValue)) {
309308
const typesInArray = [
310309
...new Set(varValue.map((item) => typeof item)),

0 commit comments

Comments
 (0)