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

Syntactic 'use strict' support #288

Closed
breyed opened this issue Jul 29, 2014 · 4 comments
Closed

Syntactic 'use strict' support #288

breyed opened this issue Jul 29, 2014 · 4 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@breyed
Copy link

breyed commented Jul 29, 2014

A nice feature would be if the TypeScript language understood 'use strict' and made it easy to apply. Although TypeScript can't help regarding the semantics of strict mode, it can help make the code cleaner and prevent a mistyping of the magic string from silently changing run-time behavior.

Currently, I often put 'use strict' as the first line a module, like this:

module Foo {
    'use strict';
    // ... rest of Foo ...
}

It would be a nice parallel with the built-in-error checking of TypeScript's type safety if I could instead use a language keyword to indicate my intent:

strict module Foo {
    // ... rest of Foo ...
}

where the latter TypeScript snippet would generate the same JavaScript as the former.

Importance of strict mode:

  • Per MDN, "strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that's not strict mode".
  • tsLint has a "use strict" rule.
@breyed
Copy link
Author

breyed commented Jul 29, 2014

Migrated from CodePlex issue 2176.

@danquirk
Copy link
Member

This doesn't really create enough value for the new syntax it's adding. You'd often have a mix of 'use strict' and a strict keyword that were functionally equivalent and if a future version of JavaScript ever needs the strict keyword we'd be in trouble (https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals)

@mhegazy
Copy link
Contributor

mhegazy commented Jul 29, 2014

One thing to note is per ES6 spec, modules and classes are parsed in strict mode. So you should get that as the default behavior when targeting ES6.

@weitzhandler
Copy link

I'd say there should be a use strict feature that doesn't allow plain JS, I guess this is probably not an option. JS is a hard coded language by nature.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision 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

5 participants