包详细信息

@voxpelli/tsconfig

voxpelli4.1kMIT16.0.0

Personal tsconfig bases

自述文件

@voxpelli/tsconfig

npm version npm downloads Follow @voxpelli@mastodon.social

My personal types in js focused tsconfig bases.

Are meant to be used with javascript code, not typescript code, hence they're having eg. noEmit: true set.

Usage

npm install --save-dev @voxpelli/tsconfig

Then add an extends to your tsconfig.json like this:

{
  "extends": "@voxpelli/tsconfig/node20.json",
  "files": [
    "index.js"
  ],
  "include": [
    "test/**/*",
  ]
}

Available configs

Generic ones

Node specific ones

These extends base-node-jsdoc with the correct lib, module, moduleResolution and target for each Node.js version.

Inspired by tsconfig/bases.

Can I use this in my own project?

Absolutely, my pleasure!

Just as with voxpelli/eslint-config I follow Semantic Versioning and thus won't do any breaking changes in any non-major releases.

Give me a ping if you use it, would be a delight to know you like it 🙂

Generate types

When publishing a module, no matter if we use JSDoc or TS syntax we need to publish type declarations.

Here's how to generate type declarations when using JSDoc,

1. Declaration specific config file

Add a new declaration specific tsconfig (eg. declaration.tsconfig.json) that extends your base tsconfig. Something like:

{
  "extends": "./tsconfig",
  "files": [],
  "exclude": [
    "test/**/*.js"
  ],
  "compilerOptions": {
    "declaration": true,
    "declarationMap": true,
    "noEmit": false,
    "emitDeclarationOnly": true
  }
}

The above excludes all top level files and all files in test/ from having types generated. If one wants eg. index.js to have auto-generated types, then one needs to either remove "files": [], to use the inherited value or explicitly add it ("files": ["index.js"],).

If one uses eg. @deprecated and wants to retain JSDoc comments in ones type declarations, then one should set "removeComments": false in the compilerOptions. By default @voxpelli/tsconfig sets "removeComments": true to keep generated types lean and DRY.

2. Add scripts

We should add scripts that uses the config file. These are examples add them to "scripts" in package.json and uses npm-run-all2 to give clean separation and enable parallel execution.

Build script

"build:0": "run-s clean",
"build:1-declaration": "tsc -p declaration.tsconfig.json",
"build": "run-s build:*",

When we run build we sequentially run all build:* using run-s.

  1. First we run clean to remove any pre-existing generated type declarations (as else they will be used as the source)
  2. Then we run tsc which generates the new type declarations thanks to it using the declaration specific tsconfig

Clean script

"clean:declarations-top": "rm -f $(find . -maxdepth 1 -type f -name '*.d.ts*' ! -name 'index.d.ts')",
"clean:declarations-lib": "rm -f $(find lib -type f -name '*.d.ts*' ! -name '*-types.d.ts')",
"clean": "run-p clean:*",

When we run clean we run all clean:* in parallel using run-p.

Both clean commands use rm -f to delete a list of files found through find. The -f flag is needed since find may return an empty list, which without -f causes rm to fail.

The find command returns all matching type declaration files. It uses three flags:

  • -maxdepth 1' is used when running in . to avoid recursing into node_modules (as we of course do not want to remove any type declarations in there)
  • -name '*.d.ts*' limits matching file names to .d.ts and .d.ts.map files. (If you generate .mts or .cts as well, then change this to *.d.*ts*)
  • -type f ensures that only files are returned

The two clean scripts are:

  • clean:declarations-top cleans all top level (.) type declarations except for index.d.ts (as that's often hand coded instead). One can remove the ! -name 'index.d.ts' or add additional ! -name sections to tweak what is ignored.
  • clean:declarations-lib recursively cleans all type declarations in lib except for those ending with -types.d.ts (as our naming convention is that all such files are hand coded). One can add additional ! -name sections to ignore further files.

Tweak type validation scripts

Assuming that we have something like the following that checks our types (if you're not using type-coverage you should start!):

"check:tsc": "tsc",
"check:type-coverage": "type-coverage --detail --strict --at-least 99 --ignore-files 'test/*'",

Then we should make sure that we run clean before we run our checks as else tsc will use the type declarations rather than the JSDoc types when validating.

So we should do something like the following, it first runs clean, then runs check:* in parallel.

"check": "run-s clean && run-p check:*",

Ensure we generate before publish

Lastly we should make sure that we generate the files before publish, something we can do by eg. adding a prepublishOnly life cyle script:

"prepublishOnly": "run-s build",

3. Ignore files in .gitignore

And something like this in your .gitignore:

# Generated types
*.d.ts
*.d.ts.map
!/lib/**/*-types.d.ts
!/index.d.ts

The ignores here (!/lib/**/*-types.d.ts, !/index.d.ts) matches the ignores we added in our clean:* scripts

Reference example

See my voxpelli/node-module-template repository for a fully functioning example of my current (and hopefully up to date) reference of this pattern.

Alternatives

My other reusable configs

更新日志

Changelog

16.0.0 (2025-08-03)

⚠ BREAKING CHANGES

  • add, improve and remove config presets (#94)

🌟 Features

  • add, improve and remove config presets (#94) (fd6f478)

🧹 Chores

  • dependents: update npm data (#88) (36422f7)
  • dependents: update npm data (#93) (0239a56)
  • deps: lock file maintenance (#87) (f1eed2f)
  • deps: update dependency @types/node to ^22.17.0 (#85) (2ae6b5a)
  • deps: update dependency npm-run-all2 to v8 (#91) (4da95d5)
  • update dependency typescript to v5.9.2 (#90) (a7417dd)

15.1.2 (2025-03-04)

🧹 Chores

15.1.1 (2025-01-06)

🧹 Chores

  • dependents: update npm data (#71) (e4d0a7b)
  • dependents: update npm data (#78) (55832d8)
  • deps: lock file maintenance (#77) (d0e9fb8)
  • deps: update dependency @types/node to ^22.10.3 (#75) (f5827bf)
  • deps: update dependency list-dependents-cli to ^2.7.1 (#76) (1702791)
  • deps: update dependency npm-run-all2 to ^7.0.2 (#74) (8fdfb2d)

15.1.0 (2024-11-25)

🌟 Features

🧹 Chores

15.0.0 (2024-09-13)

⚠ BREAKING CHANGES

  • update dependency typescript to ~5.6.2 (#54)

🌟 Features

  • add noUncheckedSideEffectImports (#56) (c93909e)

🩹 Fixes

  • update dependency typescript to ~5.6.2 (#54) (b831ea5)

14.0.0 (2024-09-06)

⚠ BREAKING CHANGES

  • update dependency typescript to ~5.5.4 (#48)
  • disable implicit @types/ imports (#50)

Features

Bug Fixes

  • update dependency typescript to ~5.5.4 (#48) (77e3fbb)

13.0.0 (2024-07-21)

⚠ BREAKING CHANGES

  • update dependency typescript to ~5.5.3 (#43)
  • require typescript 5.5 (#45)

Features

Bug Fixes

  • update dependency typescript to ~5.5.3 (#43) (6cdfdce)

12.0.1 (2024-04-29)

Bug Fixes

12.0.0 (2024-04-29)

⚠ BREAKING CHANGES

  • update typescript to ~5.5.0-beta (#37)

Miscellaneous Chores

  • update typescript to ~5.5.0-beta (#37) (a62a4a3)

11.0.0 (2024-03-10)

⚠ BREAKING CHANGES

  • update dependency typescript to ~5.4.2 (#30)

Miscellaneous Chores

  • update dependency typescript to ~5.4.2 (#30) (43a28fe)

10.1.0 (2024-03-10)

Features

10.0.0 (2023-11-21)

⚠ BREAKING CHANGES

  • update dependency typescript to ~5.3.2 (#28)

Miscellaneous Chores

  • update dependency typescript to ~5.3.2 (#28) (1da4b71)

9.0.0 (2023-10-20)

⚠ BREAKING CHANGES

  • update dependency typescript to ~5.2.2 (#21)

Miscellaneous Chores

  • update dependency typescript to ~5.2.2 (#21) (7a76845)

8.0.0 (2023-06-02)

⚠ BREAKING CHANGES

  • update dependency typescript to ~5.1.3 (#19)
  • update dependency typescript to ~5.0.4 (#17)

Miscellaneous Chores

  • update dependency typescript to ~5.0.4 (#17) (4d3f145)
  • update dependency typescript to ~5.1.3 (#19) (0d85756)