TypeScript example
TypeScriptExample
is used 132
times on 61
pages.
Pages which use TypeScriptExample
Pages
- /agents/api-reference/agents-api/ - Source
- /agents/api-reference/browse-the-web/ - Source
- /agents/api-reference/calling-agents/ - Source
- /agents/api-reference/http-sse/ - Source
- /agents/api-reference/rag/ - Source
- /agents/api-reference/run-workflows/ - Source
- /agents/api-reference/schedule-tasks/ - Source
- /agents/api-reference/store-and-sync-state/ - Source
- /agents/api-reference/using-ai-models/ - Source
- /agents/api-reference/websockets/ - Source
- /agents/index/ - Source
- /agents/model-context-protocol/mcp-agent-api/ - Source
- /agents/model-context-protocol/tools/ - Source
- /ai-gateway/providers/workersai/ - Source
- /autorag/how-to/bring-your-own-generation-model/ - Source
- /autorag/how-to/simple-search-engine/ - Source
- /autorag/tutorial/brower-rendering-autorag-tutorial/ - Source
- /bots/workers-templates/delay-action/ - Source
- /browser-rendering/platform/puppeteer/ - Source
- /browser-rendering/workers-bindings/reuse-sessions/ - Source
- /cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata/ - Source
- /cloudflare-one/tutorials/access-workers/ - Source
- /d1/get-started/ - Source
- /developer-spotlight/tutorials/fullstack-authentication-with-next-js-and-cloudflare-d1/ - Source
- /durable-objects/api/base/ - Source
- /durable-objects/api/container/ - Source
- /durable-objects/api/storage-api/ - Source
- /durable-objects/get-started/ - Source
- /images/manage-images/serve-images/serve-private-images/ - Source
- /workers-ai/features/function-calling/embedded/get-started/ - Source
- /workers-ai/get-started/workers-wrangler/ - Source
- /workers/development-testing/index/ - Source
- /workers/get-started/prompting/ - Source
- /workers/runtime-apis/nodejs/dns/ - Source
- /workers/runtime-apis/nodejs/net/ - Source
- /workers/runtime-apis/nodejs/timers/ - Source
- /workers/runtime-apis/rpc/index/ - Source
- /workers/static-assets/direct-upload/ - Source
- /workers/static-assets/migration-guides/migrate-from-pages/ - Source
- /workers/static-assets/routing/single-page-application/ - Source
- /workers/static-assets/routing/worker-script/ - Source
- /workers/testing/vitest-integration/write-your-first-test/ - Source
- /workflows/build/call-workflows-from-pages/ - Source
- /workflows/build/events-and-parameters/ - Source
- /workflows/build/rules-of-workflows/ - Source
- /workflows/build/workers-api/ - Source
Partials
The TypeScriptExample
component uses ts-blank-space
↗ to remove TypeScript-specific syntax from your example and provide a JavaScript tab. This reduces maintenance burden by only having a single example to maintain.
This component is automatically used in the GitHubCode
component when the lang
is set to ts
.
2 collapsed lines
// comment to demonstrate// collapsible sections
export default { async fetch(req, env, ctx) { if (req !== "POST") { return new Response("Method Not Allowed", { status: 405, headers: { Allow: "POST", }, }); }
await env.KV.put("foo", "bar");
return new Response(); },};
2 collapsed lines
// comment to demonstrate// collapsible sectionsinterface Environment { KV: KVNamespace;}
export default { async fetch(req, env, ctx): Promise<Response> { if (req !== "POST") { return new Response("Method Not Allowed", { status: 405, headers: { "Allow": "POST" } }); }
await env.KV.put("foo", "bar");
return new Response(); }} satisfies ExportedHandler<Environment>
import { TypeScriptExample } from "~/components";
<TypeScriptExample code={{ collapse: "1-2"}}>```ts// comment to demonstrate// collapsible sectionsinterface Environment { KV: KVNamespace;}
export default { async fetch(req, env, ctx): Promise<Response> { if (req !== "POST") { return new Response("Method Not Allowed", { status: 405, headers: { "Allow": "POST" } }); }
await env.KV.put("foo", "bar");
return new Response(); }} satisfies ExportedHandler<Environment>```</TypeScriptExample>
type: string
An optional filename, ending in .ts
.
.ts
will be replaced by .js
for the JavaScript tab.
type: boolean
If set to true
, a Run Worker in Playground
button will appear on the JavaScript tab.
type: object
Props to pass to the Expressive Code component ↗.
These props will apply to both code blocks and so options like collapse
may not work as expected, as lines may be removed from the TypeScript code.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-