如何配置TypeScript来隐藏window中所有全局变量,而只访问窗口本身?
示例:
这段代码运行正常,没有任何问题:
function foo(length: number): void {
// Console result: A number from this scope.
console.log(length);
}
但是当我删除参数length
时。林特仍然很满意。因为length
是来自window
的全局变量。See docs
function foo(): void {
// Console result: A number from window. (not expected in this case)
console.log(length);
}
期望值:
function foo(): void {
// Console result: undefined (or my global variable if exist)
// And in case the variable does not exist, the linter will cry as expected.
console.log(length);
}
我想在全局访问中隐藏窗口作用域。但是,如果我像这样调用explizit,我仍然希望访问窗口对象本身:
function foo(): void {
// This already works. But length itself without window as context should fail.
console.log(window.length);
}
是否有tsconfig或tslint选项?
发布于 2019-06-13 03:56:49
检查https://palantir.github.io/tslint/rules/no-restricted-globals/ tslint版本>= 5.13.0
https://stackoverflow.com/questions/56566942
复制相似问题