Closed
Description
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.