Skip to content

Syntactic 'use strict' support #288

Closed
@breyed

Description

@breyed

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it adds

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions