Microsoft/TypeScript

Assignments to global objects in Javascript should be global declarations

Open

#22 446 ouverte le 9 mars 2018

Voir sur GitHub
 (3 commentaires) (0 réactions) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: JavaScriptEffort: ModerateExperience EnhancementHelp WantedRescheduled

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

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

Guide contributeur