javascript - "Use Strict" needed in a TypeScript file? -
i've seen posts regarding put "use strict" line in typescript code file. question is, why have @ all?
since typescript typed language, "use strict" add?
updates
- typescript 1.8+:
"use strict";emitted in modules (read more). - typescript 2.1+:
--alwaysstrictcompiler option parses files in strict mode , emits"use strict"@ top of outputted files (read more).
you can find list of examples searching typescript's tests "in strict mode".
here's examples of code throw compile time error when "use strict";:
// future reserved keyword not allowed variable name var let, yield, public, private, protected, static, implements; // "delete" cannot called on identifier var a; delete a; // octal literals not allowed 03; there few more examples "use strict"; throw error @ runtime. example:
"use strict"; delete object.prototype; personally, don't find useful @ preventing me making mistakes in typescript , additional noise adds file makes me not bother writing it. said, starting in ts 2.1 i'll enable --alwaysstrict compiler option because adds slight additional strictness without code maintenance overhead.
Comments
Post a Comment