javascript - 即使代码中不存在,也会强制使用 strict

标签 javascript typescript es6-modules strict

我试图在我的 typescript 模块中访问function.arguments,但收到错误:

“参数”属性可能无法在严格模式函数上访问

即使 'use strict' 不存在于编译的文件中。

这是我的 tsconfig.json 设置:

    "noImplicitUseStrict": true,
    "alwaysStrict": false,
    "strict": true,

如果我删除 "noImplicitUseStrict": true 编译的文件将具有 use strict 因此该设置在 typescript 端工作(可能?)。

搜索我编译的文件,我找不到包含“strict”一词的单个文件。

我使用node编译js文件:node src/index.js

最佳答案

ES6 模块以严格模式执行。

来自 MDN Other differences between modules and standard scripts

Also, note that you might get different behavior from sections of script defined inside modules as opposed to in standard scripts. This is because modules use strict mode automatically.

关于javascript - 即使代码中不存在,也会强制使用 strict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56484791/

相关文章:

javascript - Node : Merge ES6 JS modules to one . min.js 文件

TypeScript:将映射类型与泛型一起使用

typescript - 如何检测 Typescript 中未使用的变量?

Javascript - 按数组重新排序对象数组(值)

javascript - 使用 esbuild 加载引导 JS

javascript - 无法加载类型为 "module"的脚本

javascript - 更改位置时出现 Safari 渲染问题 :fixed to position:relative

javascript - JS - 将字符串传递给 MongoDB 查询

javascript - 如何将字符串数组响应转换为javascript 2D 数组?

javascript - 是否有与 Bing 通用事件跟踪的 amp-analytics 等效的 AMP 功能?