microsoft / microsoft/TypeScript

Add option to include files in type checking, but not compiling

Open
#54,410 3 comments 35 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
1d 19h
Merged PRs (30d)
117

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.

{
  "compilerOptions": {
    "checkOutsideRootDir": true,
    "rootDir": "src",
    "outDir": "dist"
  }
}

💻 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's example tsconfig.json and compare its src/index.ts, tests/index.test.ts, and vitest.config.ts layout. Review how the proposed option should interact with rootDir, include, and exclude. Done means TypeScript type-checks all intended files while compiling only files under src into dist.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.