Microsoft/TypeScript

Assignments to global objects in Javascript should be global declarations

Open

#22.446 aperta il 9 mar 2018

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
BugDomain: JavaScriptEffort: ModerateExperience EnhancementHelp WantedRescheduled

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

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

Guida contributor