Skip to content

Commit

Permalink
Update typedef for bindings.vars
Browse files Browse the repository at this point in the history
  • Loading branch information
1000hz committed Jul 26, 2023
1 parent d4450b0 commit 67a8b9d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-snails-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Refined the type of `CfVars` from `Record<string, unknown>` to `Record<string, string | Json>`
5 changes: 2 additions & 3 deletions packages/wrangler/src/api/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { Rule } from "../config/environment";
import type { CfModule } from "../deployment-bundle/worker";
import type { StartDevOptions } from "../dev";
import type { EnablePagesAssetsServiceBindingOptions } from "../miniflare-cli/types";
import type { Json } from "miniflare";
import type { RequestInit, Response, RequestInfo } from "undici";

export interface UnstableDevOptions {
Expand All @@ -26,9 +27,7 @@ export interface UnstableDevOptions {
compatibilityFlags?: string[]; // Flags to use for compatibility checks
persist?: boolean; // Enable persistence for local mode, using default path: .wrangler/state
persistTo?: string; // Specify directory to use for local persistence (implies --persist)
vars?: {
[key: string]: unknown;
};
vars?: Record<string, string | Json>;
kv?: {
binding: string;
id: string;
Expand Down
4 changes: 3 additions & 1 deletion packages/wrangler/src/config/environment.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Json } from "miniflare";

/**
* The `Environment` interface declares all the configuration fields that
* can be specified for an environment.
Expand Down Expand Up @@ -314,7 +316,7 @@ interface EnvironmentNonInheritable {
* @default `{}`
* @nonInheritable
*/
vars: { [key: string]: unknown };
vars: Record<string, string | Json>;

/**
* A list of durable objects that your worker should be bound to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
CfPlacement,
CfTailConsumer,
} from "./worker.js";
import type { Json } from "miniflare";

export function toMimeType(type: CfModuleType): string {
switch (type) {
Expand All @@ -29,7 +30,7 @@ export type WorkerMetadataBinding =
// If you add any new binding types here, also add it to safeBindings
// under validateUnsafeBinding in config/validation.ts
| { type: "plain_text"; name: string; text: string }
| { type: "json"; name: string; json: unknown }
| { type: "json"; name: string; json: Json }
| { type: "wasm_module"; name: string; part: string }
| { type: "text_blob"; name: string; part: string }
| { type: "browser"; name: string }
Expand Down
3 changes: 2 additions & 1 deletion packages/wrangler/src/deployment-bundle/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Environment } from "../config";
import type { Route } from "../config/environment";
import type { Json } from "miniflare";

/**
* The type of Worker
Expand Down Expand Up @@ -50,7 +51,7 @@ export interface CfModule {
* A map of variable names to values.
*/
export interface CfVars {
[key: string]: unknown;
[key: string]: string | Json;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
CommonYargsArgv,
StrictYargsOptionsToInterface,
} from "./yargs-types";
import type { Json } from "miniflare";

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

export type AdditionalDevProps = {
vars?: {
[key: string]: unknown;
};
vars?: Record<string, string | Json>;
kv?: {
binding: string;
id: string;
Expand Down

0 comments on commit 67a8b9d

Please sign in to comment.