chore: Enable repo-wide type checks from source files #197
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.
It appears that a better world is possible: we can both use
Node16module resolution for builds and test, lint, and develop directly from our source files.@sirtimid previously fixed #174 and #181 over several PRs: #192 #193 #194 #195
In #194, we concluded that there was no way to run type checks without building our source files. As it turns out, this is in fact possible by disabling the
compositeconfig option1. Having done this, we now runlint:tsas part of our regular lint scripts, which reliably works without building. In addition, this also fixes type errors in ourvitest.config.tsfiles.So that we have this documented, let's review our config to understand why our new config works.
In our root
tsconfig.jsonandtsconfig.package.json(which package-leveltsconfig.jsonfiles extend), we set the following:{ "module": "Preserve", "moduleResolution": "Node10", }Using
Node10formoduleResolutioncauses TypeScript to ignore theexportsfield ofpackage.json, which enables ourpathsconfig intsconfig.packages.jsonto correctly resolve our source files. UsingPreserveformodulesimply appears to be compatible with our config. Other options, likeES2015, worked as well, but from the description of the setting it sounds like what we want.Meanwhile, our
tsconfig.test.jsonfiles have been renamed totsconfig.lint.json, and they now look like this:{ "extends": "./tsconfig.json", "compilerOptions": { "composite": false, "noEmit": true, "skipLibCheck": true }, "include": ["./src"], "exclude": [] }Due to the semantics of
extends,referencesis omitted, andincludeandexcludeoverwrite their inherited values.skipLibCheckensures that we ignore errors in dependencies, andnoEmitof course ensures that we don't actually produce any output files.We still use
Node16as ourmoduleandmoduleResolutionoptions for actual builds, as is recommended byts-bridge. There may come a time when this discrepancy causes trouble for us, but for now, it appears that we are in a happy place.Footnotes
Boundless gratitude to https://github.com/microsoft/TypeScript/issues/27069#issuecomment-2415291501 for this insight ↩