microsoft / microsoft/TypeScript

[Discussion] Better Way to Declare Globals in JavaScript files

Offen
#15,626 46 Kommentare 111 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@rbuckton arbeitet bereits daran.

Seit 11.5.2017.

Domain: JavaScript Needs Proposal Suggestion VS Code Tracked
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

Problem
Using the new checkJs feature, it is currently difficult to tell TypeScript about a global variable:

// @ts-check

myGlobal

window.myVar = 'foo';
screen shot 2017-05-05 at 4 44 20 pm

The only way around this that I know is to create a .d.ts file that defines these:

interface Window {
    myVar: string;
}

declare var myGlobal: string;

JavaScript users should not have to write *.d.ts files.

Possible Approaches
@egamma proposes that may be able to use the global comment from ESlint http://eslint.org/docs/user-guide/configuring : /* global var1, var2 */

I'd also be interested to see if we could put type information in a jsdoc somehow, something like:

/**
 * @global {string} myGlobal 
 */

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.