microsoft / microsoft/TypeScript

Assignments to global objects in Javascript should be global declarations

Open
#22,446 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: JavaScript Effort: Moderate Experience Enhancement Help Wanted Rescheduled
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied JavaScript sample using @allowJs, @checkJs, and @noEmit, and compare how assignments through global, window, and this are checked. Done means the sample reports no errors and x, y, and z are visible globally, while the optional Node/browser distinction is considered.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.