Microsoft/TypeScript

Error when accessing properties on `globalThis` with the same name of a global variable

开放

#58,345 创建于 2024年4月28日

 (5 条评论) (1 个反应) (0 位负责人)TypeScript (13,395 个派生)batch import
BugDomain: Something ElseHelp Wanted

仓库指标

星标
 (108,860 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

🔎 Search Terms

globalThis redefined error script property does not exist

🕗 Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play/?noImplicitAny=false&ts=5.5.0-beta#code/DYUwLgBAlgdgbgQ2FAJgRggXggc2AewCMkAVACygGcA6WRZdAbgChRIBPLXA44cq2vCSo0LNhABeXPEVIUadYSgBMLIA

💻 Code

let invalid1 = globalThis.invalid1;
let y = globalThis.invalid1;
let z = globalThis.invalid2;

🙁 Actual behavior

Property 'invalid1' does not exist on type 'typeof globalThis'.

🙂 Expected behavior

It should either complain about both invalid1 and invalid2, or neither

Additional information about the issue

It only happens in scripts and not in modules (if I add export {}, there are no reported errors).

贡献者指南