Microsoft/TypeScript

Assignments to global objects in Javascript should be global declarations

Open

#22,446 建立於 2018年3月9日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: JavaScriptEffort: ModerateExperience EnhancementHelp WantedRescheduled

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

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

貢獻者指南