microsoft / microsoft/TypeScript
The `strict` option is confusing since TypeScript 6
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
Acknowledgement
- I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
In TypeScript 5 and below, strict was disabled by default. The strict option could be explained as a preset that enables certain options related stricter type checking, that weren’t enabled by default. I think for many users this option was analogous to strict null checks and probably some other stuff.
My take is practically akin to the above, but with a bit more nuance. When strict was introduced in TypeScript 2.3, this was a preset that includes the 4 options strictNullChecks, noImplicitAny, noImplicitThis, and alwaysStrict. This strict mode came with the caveat that TypeScript might cause build failures, which many users have considered breaking changes in minor versions over the past years. In TypeScript 5, strict mode enabled 9 options.
The way I see it, strictness options follow several stages:
- The option does not exist.
- The option is introduced, but disabled by default.
- The option is enabled if
strictis enabled. - The option is enabled by default.
Maybe some stages are skipped. Maybe some stages are never reached.
In TypeScript 6, strict was changed to true by default. This was celebrated, because many people nowadays believe that these strict options are good. (And I agree!)
In my opinion however, this completely changed its meaning. This merges the stages 3 and 4. strict is no longer a preset to enable more strict options. Instead, it is now a preset you can use to enable 9 looser type checking options. You enable loose mode by setting an option named strict to false. You and I are aware how this came to be, but this is very weird to explain to new users. Understanding this option, requires understanding its history. Meanwhile, the explanations of the strict options are backwards. They state: true if strict; false otherwise. The real default is true unless strict is set to false. All reasoning about loose/strict mode now requires inverse reasoning. I also strongly believe there’s no point in having a loose mode at all.
In the age of LLMs this is even more confusing. Code review tools now confidently tell users they must enable strict because every blog post from before 2026 in its training data repeats this. But this information is outdated.
I believe that the strict should be either not exist or be repurposed to its old meaning.
For the option to not exist, that means:
- In a minor version:
- Deprecate
strict
- Deprecate
- In a major version
- Decouple all related options from
strict - Remove the
strictoption
- Decouple all related options from
For the option to be repurposed to its old meaning, that means:
- In a minor version:
- Temporarily deprecate
strict
- Temporarily deprecate
- In a major version:
- Decouple all currently related options from
strict - Disable
strictby default - Link new options to strict mode. I believe
verbatimModuleSyntaxis a good candidate.
- Decouple all currently related options from
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L’issue non indica alcun file sorgente né alcun test. Inizia esaminando l’opzione strict e le relative opzioni del compilatore TypeScript, confrontando le note di rilascio di TypeScript 2.3 con il comportamento attuale. Per considerare il lavoro completato, è necessario scegliere tra la rimozione di strict e il ripristino del suo significato precedente, quindi definire le relative modifiche alla migrazione e al versioning.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100