如何配置TypeScript以隐藏窗口中的所有全局变量,仅访问窗口本身?
示例:
此代码可以正常工作:
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);
}
我想在全局访问中隐藏窗口范围。但是我仍然希望访问窗口对象本身,如果我将其称为:
function foo(): void {
// This already works. But length itself without window as context should fail.
console.log(window.length);
}
是否有tsconfig或tslint选项?
答案 0 :(得分:1)
检查https://palantir.github.io/tslint/rules/no-restricted-globals/ tslint版本> = 5.13.0