GithubHelp home page GithubHelp logo

giovannibenussi / workers-types Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudflare/workers-types

0.0 1.0 0.0 398 KB

TypeScript type definitions for authoring Cloudflare Workers.

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

TypeScript 100.00%

workers-types's Introduction

Cloudflare Workers Types

⚠️ If you're upgrading from version 2, make sure to remove webworker from the lib array in your tsconfig.json. These types are now included in @cloudflare/workers-types.

Install

npm install -D @cloudflare/workers-types
-- Or
yarn add -D @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"],
    "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;
}

Auto-Generation

Types are automatically generated from the Workers runtime's source code on every release. However, these generated types don't include any generics or overloads, so to improve ergonomics, some of them are overridden.

The overrides directory contains partial TypeScript declarations. If an override has a different type classification than its generated counterpart – for example, an interface is declared to override a generated class definition – then the override is used instead of the generated output. However, if they're the same type classification (e.g. both the override and the generated output are using class), then their member properties are merged:

  • Members in the override but not in the generated type are included in the output
  • If a member in the override has the same name as one in the generated type, the generated one is removed from the output, and the override is included instead
  • If the member is declared type never in the override, it is removed from the output

If a named type override is declared as a type alias to never, that named type is removed from the output.

JSDoc comments from overrides will also be copied over to the output.

Comment overrides can also be written in Markdown. The docs directory contains these overrides. 2nd level headings are the names of top level declarations (e.g. ## `KVNamespace`), 3rd level headings are for member names (e.g. ### `KVNamespace#put`), and 4th level headings correspond to JSDoc sections for members:

  • #### Parameters: a list with parameters of the form - `param`: param description, these will be formatted as @param tags
  • #### Returns: contents will be copied as-is to the @returns tag
  • #### Examples: fenced code blocks with the language set to js, ts, javascript or typescript will be copied to @example tags

workers-types's People

Contributors

jrf0110 avatar threepointone avatar vlovich avatar 1000hz avatar ispivey avatar gregbrimble avatar github-actions[bot] avatar mrbbot avatar leo-ar avatar mathew-cf avatar jdanyow avatar bretthoerner avatar kobim avatar philipatkinson avatar third774 avatar robertcepa avatar jbampton avatar jasnell avatar qwtel avatar emanh avatar ashnewmanjones avatar motiejunas avatar dependabot[bot] avatar trjstewart avatar obsidianminor avatar kulla avatar sbfaulkner avatar petebacondarwin avatar mosch avatar mellowyarker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.