Skip to content

Commit 17780b2

Browse files
authored
Update typedef for bindings.vars (#3678)
1 parent 89cd086 commit 17780b2

File tree

6 files changed

+16
-9
lines changed

6 files changed

+16
-9
lines changed

.changeset/twenty-snails-sip.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Refined the type of `CfVars` from `Record<string, unknown>` to `Record<string, string | Json>`

packages/wrangler/src/api/dev.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Rule } from "../config/environment";
77
import type { CfModule } from "../deployment-bundle/worker";
88
import type { StartDevOptions } from "../dev";
99
import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types";
10+
import type { Json } from "miniflare";
1011
import type { RequestInit, Response, RequestInfo } from "undici";
1112

1213
export interface UnstableDevOptions {
@@ -26,9 +27,7 @@ export interface UnstableDevOptions {
2627
compatibilityFlags?: string[]; // Flags to use for compatibility checks
2728
persist?: boolean; // Enable persistence for local mode, using default path: .wrangler/state
2829
persistTo?: string; // Specify directory to use for local persistence (implies --persist)
29-
vars?: {
30-
[key: string]: unknown;
31-
};
30+
vars?: Record<string, string | Json>;
3231
kv?: {
3332
binding: string;
3433
id: string;

packages/wrangler/src/config/environment.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Json } from "miniflare";
2+
13
/**
24
* The `Environment` interface declares all the configuration fields that
35
* can be specified for an environment.
@@ -314,7 +316,7 @@ interface EnvironmentNonInheritable {
314316
* @default `{}`
315317
* @nonInheritable
316318
*/
317-
vars: { [key: string]: unknown };
319+
vars: Record<string, string | Json>;
318320

319321
/**
320322
* A list of durable objects that your worker should be bound to.

packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
CfPlacement,
88
CfTailConsumer,
99
} from "./worker.js";
10+
import type { Json } from "miniflare";
1011

1112
export function toMimeType(type: CfModuleType): string {
1213
switch (type) {
@@ -29,7 +30,7 @@ export type WorkerMetadataBinding =
2930
// If you add any new binding types here, also add it to safeBindings
3031
// under validateUnsafeBinding in config/validation.ts
3132
| { type: "plain_text"; name: string; text: string }
32-
| { type: "json"; name: string; json: unknown }
33+
| { type: "json"; name: string; json: Json }
3334
| { type: "wasm_module"; name: string; part: string }
3435
| { type: "text_blob"; name: string; part: string }
3536
| { type: "browser"; name: string }

packages/wrangler/src/deployment-bundle/worker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Environment } from "../config";
22
import type { Route } from "../config/environment";
3+
import type { Json } from "miniflare";
34

45
/**
56
* The type of Worker
@@ -50,7 +51,7 @@ export interface CfModule {
5051
* A map of variable names to values.
5152
*/
5253
export interface CfVars {
53-
[key: string]: unknown;
54+
[key: string]: string | Json;
5455
}
5556

5657
/**

packages/wrangler/src/dev.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type {
3737
CommonYargsArgv,
3838
StrictYargsOptionsToInterface,
3939
} from "./yargs-types";
40+
import type { Json } from "miniflare";
4041

4142
export function devOptions(yargs: CommonYargsArgv) {
4243
return (
@@ -303,9 +304,7 @@ This is currently not supported 😭, but we think that we'll get it to work soo
303304
}
304305

305306
export type AdditionalDevProps = {
306-
vars?: {
307-
[key: string]: unknown;
308-
};
307+
vars?: Record<string, string | Json>;
309308
kv?: {
310309
binding: string;
311310
id: string;

0 commit comments

Comments
 (0)