Skip to content

Assignments to global objects in Javascript should be global declarations #22446

Open
@sandersn

Description

@sandersn
// @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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Experience EnhancementNoncontroversial enhancementsHelp WantedYou can do thisRescheduledThis issue was previously scheduled to an earlier milestone

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions