Omiting --always-strict from 'tsconfig.json' in an ESM module

Viewed 77

ESM & "use strict"


Since the release of the following tsconfig.json flags...

  • $ tsc --module "Node16"
  • $ tsc --moduleResolution "Node16"

...I have been writing only ES6-Standardized JavaScript Modules, in "TypeScript". It is my understanding that adding "use strict"; to a JavaScript document, is like adding a parsing directive to the document (it might even be a parsing directive, I don't really know). The unique statement informs the JavaScript engine (when the JS-engine interprets the statement) that certain rules are to be enforced.

The "use strict" rules include, but are not limited to...

  • arguments.callee is not allowed
  • The with keyword is not allowed
  • An object's keys must be unique
  • and a some others that I can't recall rn...

      2B Frank, the specifics of "use strict", are not all that important in the context of this question. What really matters, is my understanding of how the use-strict rules are implemented in ES-Modules. From what I gather, they are part of the ESM-standard's specification, and therefore, there is no reason that "use strict"; needs to be added to files in an ES-Module.


The TSC --alwaysStrict Flag


    According to the TypeScriptLang.org Docs the tsc flag, "alwaysStrict": true, ensures that that files are each emitted with "use strict"; at the top of them. Considering that ESM implements the "use strict" rules, without the need for the "use strict"; statement added to the file, shouldn't it be safe to simply stop adding "alwaysStrict": true to tsconfig.json files that are in ESM projects?

Originally I asked because there were a few Repositories I followed on GitLab & GitHub, and I noticed non had omitted "alwaysStrict". They all still included it. Then another aspect was made clear to me in the comments, after the original version of this question was authored (since then I have edited the question for spelling & grammar mistakes, as well as run-on sentences, and incorrect nomenclature (which I fixed).

So, in a nutshell, what I want to do is remove "alwaysStrict" if I can do it without risk of negative consequences. I mean, if it's useless, why have it? So I would like to know either how I can know that I can safely remove it, or just what the possible implications are for removing it. Is it just a waste of space, or is there circumstances in which I may still want "alwaysStrict" in my tsconfig.json file, &/or "use strict" in my emitted JavaScript project-build files.

0 Answers
Related