Как настроить TypeScript, чтобы скрыть все глобальные переменные из окна, доступ только к самому окну?
Пример:
Этот код работает без проблем:
function foo(length: number): void {
// Console result: A number from this scope.
console.log(length);
}
но при удалении параметра length
. Линтер все еще доволен.
Потому что length
- это глобальная переменная из window
. См. Документы
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?