@cloudflare/workers-types 2.2.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,14 @@
1
1
  # Cloudflare Workers Types
2
2
 
3
+ > :warning: If you're upgrading from version 2, make sure to remove `webworker` from the `lib` array in your
4
+ > `tsconfig.json`. These types are now included in `@cloudflare/workers-types`.
5
+
3
6
  ## Install
4
7
 
5
8
  ```bash
6
- npm install @cloudflare/workers-types
9
+ npm install -D @cloudflare/workers-types
7
10
  -- Or
8
- yarn add @cloudflare/workers-types
11
+ yarn add -D @cloudflare/workers-types
9
12
  ```
10
13
 
11
14
  ## Usage
@@ -19,7 +22,7 @@ The following is a minimal `tsconfig.json` for use alongside this package:
19
22
  "compilerOptions": {
20
23
  "target": "ES2020",
21
24
  "module": "CommonJS",
22
- "lib": ["ES2020", "WebWorker"],
25
+ "lib": ["ES2020"],
23
26
  "types": ["@cloudflare/workers-types"]
24
27
  }
25
28
  }
@@ -27,7 +30,8 @@ The following is a minimal `tsconfig.json` for use alongside this package:
27
30
 
28
31
  ### Using bindings
29
32
 
30
- 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:
33
+ It's recommended that you create an ambient type file for any bindings your Worker uses. Create a file named
34
+ `bindings.d.ts` in your src directory:
31
35
 
32
36
  **`bindings.d.ts`**
33
37
 
@@ -35,8 +39,38 @@ It's recommended that you create an ambient type file for any bindings your Work
35
39
  export {};
36
40
 
37
41
  declare global {
38
- const MY_ENV_VAR: string
39
- const MY_SECRET: string
40
- const myKVNamespace: KVNamespace
42
+ const MY_ENV_VAR: string;
43
+ const MY_SECRET: string;
44
+ const myKVNamespace: KVNamespace;
41
45
  }
42
46
  ```
47
+
48
+ ## Auto-Generation
49
+
50
+ Types are automatically generated from the Workers runtime's source code on every release. However, these generated
51
+ types don't include any generics or overloads, so to improve ergonomics, some of them are overridden.
52
+
53
+ The [`overrides`](./overrides) directory contains partial TypeScript declarations. If an override has a different type
54
+ classification than its generated counterpart – for example, an `interface` is declared to override a generated `class`
55
+ definition – then the override is used instead of the generated output. However, if they're the same type classification
56
+ (e.g. both the override and the generated output are using `class`), then their member properties are merged:
57
+
58
+ - Members in the override but not in the generated type are included in the output
59
+ - If a member in the override has the same name as one in the generated type, the generated one is removed from the
60
+ output, and the override is included instead
61
+ - If the member is declared type `never` in the override, it is removed from the output
62
+
63
+ If a named type override is declared as a type alias to `never`, that named type is removed from the output.
64
+
65
+ JSDoc comments from overrides will also be copied over to the output.
66
+
67
+ Comment overrides can also be written in Markdown. The [`docs`](./docs) directory contains these overrides.
68
+ 2<sup>nd</sup> level headings are the names of top level declarations (e.g. <code>## \`KVNamespace\`</code>),
69
+ 3<sup>rd</sup> level headings are for member names (e.g. <code>### \`KVNamespace#put\`</code>), and 4<sup>th</sup> level
70
+ headings correspond to JSDoc sections for members:
71
+
72
+ - `#### Parameters`: a list with parameters of the form <code>- \`param\`: param description</code>, these will be
73
+ formatted as `@param` tags
74
+ - `#### Returns`: contents will be copied as-is to the `@returns` tag
75
+ - `#### Examples`: fenced code blocks with the language set to `js`, `ts`, `javascript` or `typescript` will be copied
76
+ to `@example` tags