从' tsconfig.json省略省略 - 图片'在ESM模块中

发布于 2025-02-06 14:38:06 字数 1504 浏览 0 评论 0 原文


ESM& “使用严格”


因为以下发布 tsconfig.json flags ...

  • $ tsc -module“ node16” << /H6>
  • $ tsc -modulereresolution“ node16”

...我一直在写ES6标准的JavaScript 模块,“打字” 。我的理解是 添加“使用严格”;对于JavaScript文档,就像 在文档中添加解析指令(甚至可能 成为解析指令,我真的不知道)。独特 声明通知JavaScript引擎 js-engine解释说明)某些规则 要执行。

“严格使用”规则包括但不限 to ...

  • garmuments.callee 不允许使用
  • 关键字的 不允许
  • 对象的键是唯一的
  • ,还有其他我可以的键't召回rn ...

&nbsp; &nbsp; &nbsp; 2b Frank,的细节“使用严格” 并非全部 这在这个问题的背景下很重要。什么 真的很重要,是我对用例如何的理解 规则是在ES模型中实施的。从我聚集的 它们是ESM标准规范的一部分,并且 因此,没有理由“使用严格”; 需要 要添加到ES模块中的文件中。


tsc - 始终标记 flag


&nbsp; &nbsp; 根据 “ ewanspertrict”:true ,确保文件是每个文件 用发出“使用严格”; 在它们的顶部。考虑 ESM实施“使用严格”规则,无需 对于“使用严格”; 语句添加到文件中,不应 只需停止将添加“ ewanspstrict”:true tsconfig.json ESM项目中的文件?

最初我问,因为我在Gitlab&amp上遵循了一些存储库。 Github,我注意到没有省略了“总是陷入困境”。他们仍然包括在内。然后,在撰写了这个问题的原始版本之后,我在评论中明确了另一个方面(从那时起,我已经编辑了拼写错误的语法错误以及跑步句子,以及不正确的命名法(我固定

,我想做的是,我想做的是“永远”,而我的意思是我的意思是没有用的。可以知道我可以安全地删除它,或者只是删除它的可能含义。 /code>文件,&amp;/或“在我发射的JavaScript项目构建文件中使用严格”

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文