microsoft / microsoft/TypeScript

The `strict` option is confusing since TypeScript 6

未关闭
#64,213 1 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

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:

  1. The option does not exist.
  2. The option is introduced, but disabled by default.
  3. The option is enabled if strict is enabled.
  4. 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
  • In a major version
    • Decouple all related options from strict
    • Remove the strict option

For the option to be repurposed to its old meaning, that means:

  • In a minor version:
    • Temporarily deprecate strict
  • In a major version:
    • Decouple all currently related options from strict
    • Disable strict by default
    • Link new options to strict mode. I believe verbatimModuleSyntax is a good candidate.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

该 issue 没有指定源文件或测试。首先检查 strict 选项及相关的 TypeScript 编译器选项,并将 TypeScript 2.3 的发布说明与当前行为进行对比。完成这项工作需要在移除 strict 和恢复其原有含义之间作出选择,然后定义相应的迁移和版本管理变更。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。