Skip to content

How do I enable strict mode in TypeScript? #4270

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

Closed
ghost opened this issue Aug 11, 2015 · 5 comments
Closed

How do I enable strict mode in TypeScript? #4270

ghost opened this issue Aug 11, 2015 · 5 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@ghost
Copy link

ghost commented Aug 11, 2015

I can't found option in Visual Studio for enable strict mode when compiling typescript to JS. Without this option Ecmascript 6 code not working in chrome, because required strict mode.

Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
@DanielRosenwasser
Copy link
Member

Just add "use strict" to the top of your file.

@DanielRosenwasser DanielRosenwasser added the Question An issue which isn't directly actionable in code label Aug 11, 2015
@DanielRosenwasser DanielRosenwasser changed the title "strict mode" compilation?! How do I enable strict mode in TypeScript? Aug 11, 2015
@ClaudenirFreitas
Copy link

IIFE with 'use strict';
(function() {
'use strict';
...
})();

@dharness
Copy link

Doesn't it seem a tad obtuse to add "use strict"; to every file? Is there any way to enforce strict mode in every file?

@kitsonk
Copy link
Contributor

kitsonk commented May 26, 2016

All ESM modules will automatically be interpreted in strict mode, as per the standard.

If the code you are compiling is to CJS, AMD or UMD, TypeScript automatically emits the 'use strict'; prolog in order to maintain the run-time compatibility with ESM.

If it is a "plain" non-modular file, then TypeScript is like JavaScript, in that it is an opt-in feature.

@mattmccutchen
Copy link
Contributor

If anyone else finds this thread in a search, the latest status is that a compiler option to enable strict mode is planned (#10758).

@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

6 participants