2

How to config TypeScript to hide all global variables from window, only access window itself?

Example:

This code works without any problems:

function foo(length: number): void {
  // Console result: A number from this scope.
  console.log(length);
}

but when I remove the parameter length. The linter is still satisfied. Because length is a global variable from window. See docs

function foo(): void {
  // Console result: A number from window. (not expected in this case)
  console.log(length);
}

Expected:

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);
}

I want to hide the window scope in global access. But I still want access the window object itself if I call it explizit like:

function foo(): void {
  // This already works. But length itself without window as context should fail.
  console.log(window.length);
}

Is there a tsconfig or tslint option?

1 Answer 1

1

Check https://palantir.github.io/tslint/rules/no-restricted-globals/ tslint version >= 5.13.0

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.