microsoft / microsoft/TypeScript
[Discussion] Better Way to Declare Globals in JavaScript files
Open
@rbuckton is already working on this.
Since May 11, 2017.
Domain: JavaScript
Needs Proposal
Suggestion
VS Code Tracked
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Problem
Using the new checkJs feature, it is currently difficult to tell TypeScript about a global variable:
// @ts-check
myGlobal
window.myVar = 'foo';
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
*/
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.