-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Add a "forceStrictMode" compiler option #7209
Comments
One thing to note, modules and classes are already parsed in strict mode, in accordance with ES6 spec. Starting with TS 1.8 I am assuming you are not using modules. |
Hi @mhegazy, I've tried to add such a "forceStrictMode" compiler option in a fork with this commit. This adds the behavior that would work for us (if the option is enabled, the compiler treats all files in strict mode, and also emits a "use strict" directive for javascript files). However I don't know if this is done correctly since I don't know the internals of TypeScript, or if it is feasible to add this option directly into TypeScript (a TODO would be to check "noImplicitUseStrict" against "forceStrictMode"). What do you think? Thanks! |
We didn't want to add another commandline flag for this. This is pretty easy to enforce with an external tool, at which point the compiler picks up from there with the strict mode checks. |
I was going to suggest this as well, but see this has been closed as Too Complex. In any event, if you ever decide to revisit this issue, consider this a +1 vote for this feature. |
Hi,
first, thanks for all the great work on Typescript!
It would be very nice if the compiler had some
"forceStrictMode"
option which, if enabled, treats all TS files in the project as if they had"use strict";
before their first statement (so the TS compiler would apply strict mode checking to all TS files even if they do not have the"use strict";
statement, and also emit the"use strict";
statement in the transpiled JS files).In our project we use TypeScript for a HTML5 App and we want to use strict mode for every file, and such an option would remove the need from writing "use strict" at the top of every file (sometimes we might forget this when adding a new TS file).
We also use Typescript to be able to execute JavaScript on a Server which runs it using Jint interpreter, which allows to enable strict mode for both parsing and executing the JS even if it doesn't declare "use strict". The option would allow us to reflect this behavior to the TypeScript compiler used in an Editor for transpiling the TS scripts to JS which are executed by this interpreter.
What do you think about it?
Thanks!
The text was updated successfully, but these errors were encountered: