Skip to content

Commit

Permalink
fix(typescript): settle review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Arrowood committed Sep 25, 2023
1 parent 81eff4b commit f8d3326
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 30 deletions.
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,13 @@ module.exports = {

## TypeScript

This guide provides multiple TypeScript configuration options. These configs correlate to the major Node.js versions and configure the appropriate `lib`, `module`, `target`, and `moduleResolution` settings. The table below specifies the config name with the Node.js version.
This style guide provides multiple TypeScript configs. These configs correlate to the LTS Node.js versions, providing the appropriate `lib`, `module`, `target`, and `moduleResolution` settings for each version. The following configs are available:

| Node.js Version | TypeScript Config |
| --------------- | ----------------------- |
| v16 | `typescript/node16` |
| v18 | `typescript/node18` |
| v20 | `typescript/node20` |
| v20 (ESM) | `typescript/node20-esm` |

> When using `node20-esm`, don't forget to set `{ "type": "module" }` in your `package.json`
| Node.js Version | TypeScript Config |
| --------------- | --------------------------------------- |
| v16 | `@vercel/style-guide/typescript/node16` |
| v18 | `@vercel/style-guide/typescript/node18` |
| v20 | `@vercel/style-guide/typescript/node20` |

To use the shared TypeScript config, set the following in `tsconfig.json`.

Expand All @@ -221,8 +218,4 @@ To use the shared TypeScript config, set the following in `tsconfig.json`.
}
```

The base TypeScript config is also available as `@vercel/style-guide/typescript` which only specifies a set of general rules such as `esModuleInterop`, `strict`, and `noUncheckedIndexedAccess`.

> Why do `node20` and `node20-esm` use the same `lib` and `target` as `node18`?
>
> The lib and target fields are the same because Node.js v18 implemented support for some ES2023 methods. And since TypeScript does not allow us to specify types for individual features (and rather sets of features such as `ESNext.AsyncIterable`) we must use `ES2023` in the `lib` array for Node.js v18. Furthermore, once TypeScript releases a `"target": "ES2023"`, then the Node.js v20 configuration will be updated to that (assuming Node.js v20 fully supports ES2023).
The base TypeScript config is also available as [`@vercel/style-guide/typescript`](./typescript/tsconfig.base.json) which only specifies a set of general rules. You should inherit from this file when setting custom `lib`, `module`, `target`, and `moduleResolution` settings.
4 changes: 2 additions & 2 deletions typescript/tsconfig.node16.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2021"],
"lib": ["es2021"],
"module": "node16",
"target": "ES2021",
"target": "es2021",
"moduleResolution": "node16"
}
}
4 changes: 2 additions & 2 deletions typescript/tsconfig.node18.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2023"],
"lib": ["es2023"],
"module": "node16",
"target": "ES2022",
"target": "es2023",
"moduleResolution": "node16"
}
}
10 changes: 0 additions & 10 deletions typescript/tsconfig.node20-esm.json

This file was deleted.

4 changes: 2 additions & 2 deletions typescript/tsconfig.node20.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2023"],
"lib": ["es2023"],
"module": "node16",
"target": "ES2022",
"target": "es2023",
"moduleResolution": "node16"
}
}

0 comments on commit f8d3326

Please sign in to comment.