microsoft / microsoft/TypeScript

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

Aperta
#54,410 3 commenti 35 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il tsconfig.json di esempio dell’issue e confronta la struttura di src/index.ts, tests/index.test.ts e vitest.config.ts. Verifica come l’opzione proposta dovrebbe interagire con rootDir, include ed exclude. Il lavoro è completato quando TypeScript esegue il controllo dei tipi su tutti i file previsti, ma compila in dist solo i file presenti sotto src.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
build-system, compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.