microsoft/TypeScript

Assignments to global objects in Javascript should be global declarations

sandersn opened this issue · 3 comments

// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: a.js
global.x = 1
window.y = 2
this.z = 3

var n = x + y + z

Expected behavior:
No error, and x, y and z are visible globally.

Actual behavior:
Errors:

  1. Can't find name 'global'
  2. 'Window' has no property 'y'
  3. Cannot find name 'x', 'y' or 'z'

Ideally, global should only be visible when targetting node and window should only be visible when targetting the browser. It's not a requirement, though.

Should be covered by #14052 and #19816

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

Not really a dupe of those other issues; this one is about assignment declarations on a value (window) creating properties in the global symbol table.

#14052 is just about types.
#19816 is about making window show properties from globalThis, which is backward from this feature.