jayphelps / workers-types

TypeScript type definitions for authoring Cloudflare Workers.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cloudflare Workers Types

Install

npm install @cloudflare/workers-types
-- Or
yarn add @cloudflare/workers-types

Usage

The following is a minimal tsconfig.json for use alongside this package:

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "CommonJS",
    "lib": ["ES2020", "WebWorker"],
    "types": ["@cloudflare/workers-types"]
  }
}

Using bindings

It's recommended that you create an ambient type file for any bindings your Worker uses. Create a file named bindings.d.ts in your src directory:

bindings.d.ts

export {};

declare global {
  const MY_ENV_VAR: string
  const MY_SECRET: string
  const myKVNamespace: KVNamespace
}

About

TypeScript type definitions for authoring Cloudflare Workers.

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:TypeScript 100.0%