Description
Suggestion
π Search Terms
rootDir
exclude
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β 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 the rootDir
. 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:
βββ package.json
βββ src
βΒ Β βββ index.ts
βββ tests
βΒ Β βββ index.test.ts
βββ tsconfig.json
βββ vitest.config.ts
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 of tsconfig.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 of extends
/ 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.