Skip to content

Commit

Permalink
feat(typescript): add tsconfigs for node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Arrowood committed Sep 5, 2023
1 parent 1c75e76 commit 7568ea5
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 18 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,23 @@ 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.

| 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`
To use the shared TypeScript config, set the following in `tsconfig.json`.

```json
{
"extends": "@vercel/style-guide/typescript"
"extends": "@vercel/style-guide/typescript/node16"
}
```

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`.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
},
"license": "MPL-2.0",
"exports": {
"typescript/base": "./typescript/tsconfig.base.json",
"typescript/node": "./typescript/tsconfig.node.json",
"typescript/web": "./typescript/tsconfig.web.json"
"./typescript": "./typescript/tsconfig.base.json",
"./typescript/node16": "./typescript/tsconfig.node16.json",
"./typescript/node18": "./typescript/tsconfig.node18.json",
"./typescript/node20": "./typescript/tsconfig.node20.json",
"./typescript/node20-esm": "./typescript/tsconfig.node20-esm.json"
},
"main": "index.js",
"files": [
Expand Down
12 changes: 0 additions & 12 deletions typescript/tsconfig.node.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"target": "ES2015"
"lib": ["ES2021"],
"module": "node16",
"target": "ES2021",
"moduleResolution": "node16"
}
}
10 changes: 10 additions & 0 deletions typescript/tsconfig.node18.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2023"],
"module": "node16",
"target": "ES2022",
"moduleResolution": "node16"
}
}
10 changes: 10 additions & 0 deletions typescript/tsconfig.node20-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2023"],
"module": "NodeNext",
"target": "ES2022",
"moduleResolution": "NodeNext"
}
}
10 changes: 10 additions & 0 deletions typescript/tsconfig.node20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2023"],
"module": "node16",
"target": "ES2022",
"moduleResolution": "node16"
}
}

0 comments on commit 7568ea5

Please sign in to comment.