Strict type-checking on a per-file basis "@ts-strict"
See original GitHub issueSearch Terms
strict per file
Suggestion
Currently in the process of converting a moderate-sized javascript project to typescript. Would love to be able to enable strict type-checks on a per-file basis.
Use Cases
Enabling strict mode for the entire project is a daunting task that presents a barrier to adoption (and using typescript without strict mode turned on is like locking the doors on a convertible…it’s probably better than nothing, but it’s not gonna keep you safe).
Examples
//@ts-strict
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. new expression-level syntax)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:328
- Comments:28 (2 by maintainers)
Top Results From Across the Web
Controlling Type Checking Strictness in TypeScript
There is a TypeScript compiler option called strict . This turns on a set of type checking rules and is referred to as...
Read more >Documentation - tsc CLI Options - TypeScript
Flag Type Default
‑‑allowJs boolean false
‑‑allowUmdGlobalAccess boolean false
‑‑allowUnreachableCode boolean
Read more >How strict is Typescript's strict mode? - DEV Community
According to the docs, when Typescript strict mode is set to on, it will validate your code using the strict type rules under...
Read more >Controlling type checking strictness | Learn TypeScript
The starter project has a compiler option switch on called strict . This turns on a set of type checking rules and is...
Read more >TypeScript -- force strong strict typed mode for all? - Reddit
With the strict options enabled, you are still required to specify the type in situations where it cannot be inferred (type of function...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Would love to see this feature implemented as well. We have quite sizeable project and going “all strict” is not an option right now.
While there are no built-in features like this in Typescript, we’ve created typescript-strict-plugin which allows you to turn on strict-mode in specific files or routes. Hope it helps!