Skip to content
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

Closed
T18970237136 opened this issue Feb 24, 2016 · 4 comments
Closed

Suggestion: Add a "forceStrictMode" compiler option #7209

T18970237136 opened this issue Feb 24, 2016 · 4 comments
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@T18970237136
Copy link
Contributor

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!

@mhegazy
Copy link
Contributor

mhegazy commented Feb 24, 2016

One thing to note, modules and classes are already parsed in strict mode, in accordance with ES6 spec. Starting with TS 1.8 "use strict" prologue is emitted by default for modules.

I am assuming you are not using modules.

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 24, 2016
@T18970237136
Copy link
Contributor Author

Hi @mhegazy,
thanks. Yes, we do not use modules. We would like to force strict mode even for .ts files which doesn't contain classes etc.

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!

@RyanCavanaugh RyanCavanaugh added Too Complex An issue which adding support for may be too complex for the value it adds and removed In Discussion Not yet reached consensus labels Mar 8, 2016
@RyanCavanaugh
Copy link
Member

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.

@DavidKDeutsch
Copy link

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.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

4 participants