Add stricter TypeScript type checking #25
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Most of this message is copied from:
After doing more research, it appears tsconfig.json is more broadly supported by editors and IDEs than jsconfig.json. For example, IntelliJ IDEA/WebStorm won't recognize it unless added to Settings > Editor > File Types > TypeScript.
Related changes include:
Fixed the problems with vitest.config.js and ci/vitest.config.js such that the
// @ts-nocheck
directive is no longer necessary. Used...(configDefaults.coverage.exclude || [])
to avoid type errors due to configDefaults.coverage.exclude potentially being undefined.Moved a bunch of compiler options from the
pnpm typecheck
script into tsconfig.json.Added the
rimraf
npm to make surepnpm prepack
generates a newtypes/
directory without stale content.Added @types/{jsdom,istanbul-lib-coverage} as production dependencies.
Bumped vitest to 1.2.0.
Set .eslintrc to disable the no-undefined-types rule by extending "plugin:jsdoc/recommended-typescript-flavor-error". This is because the Handlebars types in lib/parser.js weren't trivial to replicate, and TypeScript finds those types just fine. This was based on advice from:
And:
More background:
no-undefined-types
additional files or have it auto-detect them (and finding unused types within the same set of files); avoid defects of tampering withno-unused-vars
gajus/eslint-plugin-jsdoc#99At the same time, extending "recommended-typescript-flavor-error" required adding the
// eslint-disable-next-line no-unused-vars
directive before each set of imports from lib/types.js. (Or adding// eslint-disable-line no-unused-vars
on the same line if possible.)Added 'jsdoc-plugin-typescript' to the build to handle the TypeScript
import().Type
directives. This ended up pulling in the 'es-abstract' module, which blew up the pnpm-lock.yaml file. If I get an itch, I'll implement my own plugin one day and replace it.Finally, it seems IntelliJ IDEA's JSDoc type checking is stronger than TypeScript and VSCode. Fixed a few JSDoc type parameters to eliminate warnings in IntelliJ as well.