javascript - 在 Typescript 严格模式函数上访问被调用者?
问题描述
我正在向这个库添加访问arugments.callee
. 在项目的tsconfig.json
I set"strict": false
中,导致这个迷你测试工作:
function check() {
console.log(arguments.callee.name);
}
这样可行。现在,如果我像这样导入要运行测试的库部分:
import {isNumberInRange} from './is';
function check() {
console.log(arguments.callee.name);
// isNumberInRange(1,0,1);
}
check();
即使我实际上没有运行isNumberInRange
函数 typescript 仍然会记录以下内容:
TypeError: 'caller'、'callee' 和 'arguments' 属性可能无法在严格模式函数或参数对象上访问以在检查时调用它们(/home/ole/Github/is/src/test.ts:4 :27)
我还需要做什么才能启用呼叫arguments.callee.name
?
解决方案
除了"strict": false
还加"noImplicitUseStrict": true
。
TypeScript 会自己添加严格模式,这需要禁用。
如何做到这一点已经在这里得到解答:prevent-use-strict-in-typescript
您可以通过使用 --noImplicitUseStrict 编译器选项进行编译来做到这一点——将“noImplicitUseStrict”:true 添加到 tsconfig.json 中的“compilerOptions”。这样做会阻止编译器发出“use strict”。
推荐阅读
- javascript - JavaScript,在数组内创建对象,仅包含 2 个对象
- r - R:以设定的速率为前向增长建模
- google-cloud-platform - GKE:区域配额不足以满足请求:资源“IN_USE_ADDRESSES”
- android - 使子视图组向下填充父组的其余部分
- windows - 删除了变量赋值副作用的感叹号
- oracle - 减小oracle数据库docker镜像的大小
- java - 调整大小/扩展 div 大小后,在释放操作时它会恢复到默认大小
- python - 尝试阈值时清空 Pandas 数据框
- python - 如何基于多个正则表达式创建新列
- java - 无法加载在 Docker 中运行的 Spring Boot 应用程序