首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何配置TypeScript对window隐藏所有全局变量,但访问窗口本身?

如何配置TypeScript对window隐藏所有全局变量,但访问窗口本身?
EN

Stack Overflow用户
提问于 2019-06-13 00:46:57
回答 1查看 470关注 0票数 2

如何配置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选项?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-13 03:56:49

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56566942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档