-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add option to include files in type checking, but not compiling #54410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The intended configuration solution for this is project references, but I can appreciate how this is a simple approach to the same problem. |
I have a feeling this is exactly the problem I am hitting... I would love to be able to "Find All References", but I believe it is excluded. With the following: tsconfig.json
tsconfig.app.json
tsconfig.spec.json
Doing a "Find all references" in a If I open the spec file, now all references of that file are found. |
Since the files to be compiled are usually a subset of those being type-checked, I suggest introducing an This way, a single property ensures that the set of files to be compiled is a subset of the files to be typechecked, which greatly simplifies things. The most common way this problem is currently solved is with a
For these reasons, many people, even TypeScript experts, avoid typechecking files that will not be compiled (configuration files, scripts, tests, etc.), or they do so with JSDoc annotations. I can see this happening even in the monorepo templates well well-maintained by turborepo.
@RyanCavanaugh I've read all the project references documentation and I don't see how they could solve this problem. Is there something I'm missing? |
Suggestion
π Search Terms
rootDir
exclude
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
I would love to have an option to include files for type checking, but not compiling.
One solution would be to add an option (
checkOutsideRootDir
?) to support type checking files outside therootDir
. An alternative way could be to provide separate glob patterns for type checking and compiling.π Motivating Example
Letβs say you are testing you project with Vitest. You probably have a file structure that looks something like this:
Previously you needed two TypeScript configuration files, one for type checking everything, and one for compiling your source code. With this new option enabled, TypeScript will type check all TypeScript files, but it will only compile the files from the
rootDir
directory.π» Use Cases
Currently I feel like there is no proper way to configure TypeScript for both type checking and compiling. Some special configuration is needed to compile source code, and type check tests / config files, but exclude those from the build.
Often repos end up with
tsconfig.json
and something along the way oftsconfig.build.json
,tsconfig-prod.json
,dev.tsconfig.json
, or something along those lines. Itβs not consistent across the ecosystem. This file then uses a mix ofextends
/include
/exclude
to create complex configurations. Alternatively people just exclude certain files, not being aware they are being excluded from type checking as well. Or they use an alternative tool for building.Regardless of what people come up with, it often leads to awkward configurations.
The text was updated successfully, but these errors were encountered: