Skip to content

Commit dcd39c9

Browse files
committed
fixups
1 parent e20e73b commit dcd39c9

File tree

8 files changed

+34
-19
lines changed

8 files changed

+34
-19
lines changed

src/content/docs/ai-gateway/integrations/worker-binding-methods.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ binding = "AI"
2525

2626
This configuration sets up the AI binding accessible in your Worker code as `env.AI`.
2727

28-
<Render file="wrangler-typegen" />
28+
<Render file="wrangler-typegen" product="workers" />
2929

3030
## 2. Basic Usage with Workers AI + Gateway
3131

src/content/docs/browser-rendering/platform/playwright.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ binding = "MYBROWSER"
4242

4343
</WranglerConfig>
4444

45-
<Render file="wrangler-typegen" />
45+
<Render file="wrangler-typegen" product="workers" />
4646

4747
Install the npm package:
4848

src/content/docs/pages/framework-guides/deploy-a-qwik-site.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The following code block shows an example of accessing a KV namespace in QwikCit
6868
// ...
6969

7070
export const useGetServerTime = routeLoader$(({ platform }) => {
71-
// the type `KVNamespace` comes from types generated by running `wrangler types`
71+
// the type `KVNamespace` comes from runtime types generated by running `wrangler types`
7272
const { MY_KV } = (platform.env as { MY_KV: KVNamespace }));
7373

7474
return {

src/content/docs/vectorize/reference/client-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,4 @@ Refer to the [bindings documentation](/workers/wrangler/configuration/#vectorize
218218

219219
## TypeScript Types
220220

221-
<Render file="wrangler-typegen" />
221+
<Render file="wrangler-typegen" product="workers" />

src/content/docs/workers/runtime-apis/rpc/typescript.mdx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,40 @@ head:
88
content: Workers RPC — TypeScript
99
description: How TypeScript types for your Worker or Durable Object's RPC
1010
methods are generated and exposed to clients
11-
1211
---
1312

1413
The types generated by running [`wrangler types`](/workers/languages/typescript/#generate-types) provide the `Service` and `DurableObjectNamespace` types, each of which accepts a single type parameter for the server-side [`WorkerEntrypoint`](/workers/runtime-apis/bindings/service-bindings/rpc) or [`DurableObject`](/durable-objects/best-practices/create-durable-object-stubs-and-send-requests/#call-rpc-methods) types.
14+
We recommend extending the `Env` type generated in a separate file and providing the type parameter there, so that these are not overwritten when you run `wrangler types` again.
15+
16+
For example, if you had a Worker with bindings to a WorkerEntrypoint called `SumService` and a Durable Object called `Counter`, your `wrangler types` output would look like this:
1517

16-
Using higher-order types, we automatically generate client-side stub types (e.g., forcing all methods to be async).
18+
```ts title="worker-configuration.d.ts"
19+
// Generated by Wrangler by running `wrangler types --env-interface BaseEnv`
20+
declare namespace Cloudflare {
21+
interface Env {
22+
SUM_SERVICE: Fetcher;
23+
COUNTER_OBJECT: DurableObjectNamespace;
24+
}
25+
}
26+
interface BaseEnv extends Cloudflare.Env {}
27+
```
1728

18-
For example:
29+
Then extend `Env` type in a separate file:
1930

20-
```ts
21-
interface Env {
22-
SUM_SERVICE: Service<SumService>;
23-
COUNTER_OBJECT: DurableObjectNamespace<Counter>
31+
```ts title="env.d.ts"
32+
interface Env extends BaseEnv {
33+
SUM_SERVICE: Service<import("../path/to/your/bound/worker").SumService>;
34+
COUNTER_OBJECT: DurableObjectNamespace<import("../path/to/your/do").Counter>;
2435
}
36+
```
37+
38+
Using higher-order types, we automatically generate client-side stub types (e.g., forcing all methods to be async). In the following example, `env.SUM_SERVICE.sum` will be typed as defined in the `SumService` WorkerEntrypoint.
2539

40+
```ts title="src/index.ts"
2641
export default {
27-
async fetch(req, env, ctx): Promise<Response> {
28-
const result = await env.SUM_SERVICE.sum(1, 2);
29-
return new Response(result.toString());
30-
}
42+
async fetch(req, env, ctx): Promise<Response> {
43+
const result = await env.SUM_SERVICE.sum(1, 2);
44+
return new Response(result.toString());
45+
},
3146
} satisfies ExportedHandler<Env>;
3247
```

src/content/docs/workers/vite-plugin/tutorial.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
description: Create a React SPA with an API Worker using the Vite plugin
77
---
88

9-
import { PackageManagers, WranglerConfig } from "~/components";
9+
import { PackageManagers, WranglerConfig, Render } from "~/components";
1010

1111
This tutorial takes you through the steps needed to adapt a Vite project to use the Cloudflare Vite plugin.
1212
Much of the content can also be applied to adapting existing Vite projects and to front-end frameworks other than React.

src/content/docs/workflows/build/workers-api.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ script_name = "billing-worker"
212212

213213
</WranglerConfig>
214214

215-
<Render file="wrangler-typegen" />
215+
<Render file="wrangler-typegen" product="workers" />
216216

217217
## Workflow
218218

src/content/docs/workflows/examples/send-invoices.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sidebar:
1212
description: Send invoice when shopping cart is checked out and paid for
1313
---
1414

15-
import { TabItem, Tabs, WranglerConfig } from "~/components";
15+
import { TabItem, Tabs, WranglerConfig, Render } from "~/components";
1616

1717
In this example, we implement a Workflow for an e-commerce website that is triggered every time a shopping cart is created.
1818

@@ -219,4 +219,4 @@ name = "SEND_EMAIL"
219219

220220
</WranglerConfig>
221221

222-
<Render file="wrangler-typegen" />
222+
<Render file="wrangler-typegen" product="workers" />

0 commit comments

Comments
 (0)