microsoft / microsoft/TypeScript
The `strict` option is confusing since TypeScript 6
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
### Acknowledgement
- [x] 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](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html), 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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Issue không nêu tên tệp nguồn hay các bài kiểm thử nào. Hãy bắt đầu bằng việc xem xét tùy chọn `strict` và các tùy chọn liên quan của trình biên dịch TypeScript, đồng thời so sánh release notes của TypeScript 2.3 với hành vi hiện tại. Để hoàn tất, cần lựa chọn giữa việc loại bỏ `strict` và khôi phục ý nghĩa trước đây của nó, sau đó xác định các thay đổi tương ứng về migration và versioning.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100