Skip to content

Commit 4340524

Browse files
committed
Added documentation for new wrangler types --check flag
1 parent 006a23a commit 4340524

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/content/docs/workers/languages/typescript/index.mdx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ Most projects will have existing build and development scripts, as well as some
129129
}
130130
```
131131

132-
We recommend you commit your generated types file for use in CI. Alternatively, you can run `wrangler types` before other CI commands, as it should not take more than a few seconds. For example:
132+
We recommend you commit your generated types file for use in CI. You can run `wrangler types` before other CI commands, as it should not take more than a few seconds. For example:
133133

134134
<Tabs> <TabItem label="npm">
135135

@@ -157,6 +157,36 @@ We recommend you commit your generated types file for use in CI. Alternatively,
157157
158158
</TabItem> </Tabs>
159159
160+
Alternatively, if you commit your generated types file and want to verify it stays up-to-date in CI, you can use the `--check` flag:
161+
162+
<Tabs> <TabItem label="npm">
163+
164+
```yaml
165+
- run: npx wrangler types --check
166+
- run: npm run build
167+
- run: npm test
168+
```
169+
170+
</TabItem> <TabItem label="yarn">
171+
172+
```yaml
173+
- run: yarn wrangler types --check
174+
- run: yarn build
175+
- run: yarn test
176+
```
177+
178+
</TabItem> <TabItem label="pnpm">
179+
180+
```yaml
181+
- run: pnpm wrangler types --check
182+
- run: pnpm run build
183+
- run: pnpm test
184+
```
185+
186+
</TabItem> </Tabs>
187+
188+
This fails the CI job if the committed types file is out-of-date, prompting developers to regenerate and commit the updated types.
189+
160190
### Resources
161191

162192
- [TypeScript template](https://github.com/cloudflare/workers-sdk/tree/main/packages/create-cloudflare/templates/hello-world/ts)

src/content/docs/workers/wrangler/commands.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,10 @@ wrangler types [<PATH>] [OPTIONS]
980980
- Control the types that Wrangler generates for `vars` bindings.
981981
- If `true`, (the default) Wrangler generates literal and union types for bindings (e.g. `myVar: 'my dev variable' | 'my prod variable'`).
982982
- If `false`, Wrangler generates generic types (e.g. `myVar: string`). This is useful when variables change frequently, especially when working across multiple environments.
983+
- `--check` <Type text="boolean" /> <MetaInfo text="optional" />
984+
- Check if the generated types at the specified path are up-to-date without regenerating them.
985+
- Exits with code 0 if types are up-to-date, or code 1 if types are out-of-date.
986+
- Useful for CI/CD pipelines and pre-commit hooks to ensure types have been regenerated after configuration changes.
983987
- `--config`, `-c` <Type text="string[]" /> <MetaInfo text="optional" />
984988
- Path(s) to [Wrangler configuration file](/workers/wrangler/configuration/). If the Worker you are generating types for has service bindings or bindings to Durable Objects, you can also provide the paths to those configuration files so that the generated `Env` type will include RPC types. For example, given a Worker with a service binding, `wrangler types -c wrangler.toml -c ../bound-worker/wrangler.toml` will generate an `Env` type like this:
985989
```ts

0 commit comments

Comments
 (0)