diff --git a/README.md b/README.md index aa8aead..b71f90a 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/package.json b/package.json index bb6aa0c..b1893f6 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/typescript/tsconfig.node.json b/typescript/tsconfig.node.json deleted file mode 100644 index 958f13f..0000000 --- a/typescript/tsconfig.node.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "./tsconfig.base.json", - "compilerOptions": { - "declaration": true, - "lib": ["ES2021"], - "moduleResolution": "nodenext", - "resolveJsonModule": true, - "sourceMap": true, - "target": "ES2021" - } -} diff --git a/typescript/tsconfig.web.json b/typescript/tsconfig.node16.json similarity index 53% rename from typescript/tsconfig.web.json rename to typescript/tsconfig.node16.json index 6167e28..e37392a 100644 --- a/typescript/tsconfig.web.json +++ b/typescript/tsconfig.node16.json @@ -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" } } diff --git a/typescript/tsconfig.node18.json b/typescript/tsconfig.node18.json new file mode 100644 index 0000000..ff89946 --- /dev/null +++ b/typescript/tsconfig.node18.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.base.json", + "compilerOptions": { + "lib": ["ES2023"], + "module": "node16", + "target": "ES2022", + "moduleResolution": "node16" + } +} diff --git a/typescript/tsconfig.node20-esm.json b/typescript/tsconfig.node20-esm.json new file mode 100644 index 0000000..0b40a79 --- /dev/null +++ b/typescript/tsconfig.node20-esm.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.base.json", + "compilerOptions": { + "lib": ["ES2023"], + "module": "NodeNext", + "target": "ES2022", + "moduleResolution": "NodeNext" + } +} diff --git a/typescript/tsconfig.node20.json b/typescript/tsconfig.node20.json new file mode 100644 index 0000000..ff89946 --- /dev/null +++ b/typescript/tsconfig.node20.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.base.json", + "compilerOptions": { + "lib": ["ES2023"], + "module": "node16", + "target": "ES2022", + "moduleResolution": "node16" + } +}