Skip to content

Commit

Permalink
feat(typescript): add multiple tsconfigs (#60)
Browse files Browse the repository at this point in the history
Co-authored-by: Brody McKee <mrmckeb@users.noreply.github.com>
  • Loading branch information
Ethan-Arrowood and mrmckeb committed Nov 22, 2023
1 parent 75286d0 commit 3991e02
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -202,10 +202,20 @@ module.exports = {

## TypeScript

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 | `@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`.

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

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.
10 changes: 9 additions & 1 deletion package.json
Expand Up @@ -11,11 +11,19 @@
"url": "https://github.com/vercel/style-guide.git"
},
"license": "MPL-2.0",
"exports": {
"./eslint/*": "./eslint/*.js",
"./prettier": "./prettier/index.js",
"./typescript": "./typescript/tsconfig.base.json",
"./typescript/node16": "./typescript/tsconfig.node16.json",
"./typescript/node18": "./typescript/tsconfig.node18.json",
"./typescript/node20": "./typescript/tsconfig.node20.json"
},
"main": "index.js",
"files": [
"eslint",
"prettier",
"typescript.json"
"typescript"
],
"scripts": {
"eslint-check": "eslint --max-warnings=0 .",
Expand Down
2 changes: 2 additions & 0 deletions typescript.json → typescript/tsconfig.base.json
@@ -1,5 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Vercel Base",
"docs": "https://github.com/vercel/style-guide",
"compilerOptions": {
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down
12 changes: 12 additions & 0 deletions typescript/tsconfig.node16.json
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"display": "Vercel Node 16",
"docs": "https://github.com/vercel/style-guide",
"compilerOptions": {
"lib": ["es2021"],
"module": "node16",
"target": "es2021",
"moduleResolution": "node16"
}
}
12 changes: 12 additions & 0 deletions typescript/tsconfig.node18.json
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"display": "Vercel Node 18",
"docs": "https://github.com/vercel/style-guide",
"compilerOptions": {
"lib": ["es2023"],
"module": "node16",
"target": "es2023",
"moduleResolution": "node16"
}
}
12 changes: 12 additions & 0 deletions typescript/tsconfig.node20.json
@@ -0,0 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "./tsconfig.base.json",
"display": "Vercel Node 20",
"docs": "https://github.com/vercel/style-guide",
"compilerOptions": {
"lib": ["es2023"],
"module": "node16",
"target": "es2023",
"moduleResolution": "node16"
}
}

0 comments on commit 3991e02

Please sign in to comment.