Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some global properties missing from window but accessible directly #14590

Closed
ghost opened this issue Mar 11, 2017 · 3 comments
Closed

some global properties missing from window but accessible directly #14590

ghost opened this issue Mar 11, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@ghost
Copy link

ghost commented Mar 11, 2017

TypeScript Version: 2.1.1

Code

/**
 * typescript says `[ts] Property 'x' does not exist on type 'Window'.`
 * for all of these, but they all exist and work in browsers:
 */
window.Document
window.eval // <- this one is useful for "indirect eval" - i ran into this bug once earlier
window.EventTarget
window.Function
window.MouseEvent
window.HTMLElement
window.DocumentFragment

/**
 * same thing here, this is more similar to what i was doing when i found this bug
 */
var iframe = document.createElement("iframe");
iframe.contentWindow.Document
// etc etc

// somewhat important note: there are probably more, i just quickly came up with these

/**
 * they work in typescript if accessed this way:
 */
Document
eval
EventTarget
Function
MouseEvent
HTMLElement
DocumentFragment

(you can paste it in the typescript playground here: https://www.typescriptlang.org/play/)

Expected behavior:

there should be no errors, all the properties should exist on window

Actual behavior:

the properties don't exist on window but seem to exist in a "global scope" somehow so they're only visible to typescript when accessed directly

normally i guess i could just not use the window. prefix for accessing these properties, but that's not an option for indirect eval via window.eval or accessing the properties from other windows (iframes, window.opener, window.top, etc)

@blakeembrey
Copy link
Contributor

Unfortunately it's a result of these types being separate to the global scope in TypeScript. You might be interested in a related issue that could improve the situation: #14052. For now, all the definitions would need to be duplicated into window (and global in node).

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Mar 11, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Feb 8, 2018

Duplicate of #19816

@mhegazy mhegazy marked this as a duplicate of #19816 Feb 8, 2018
@mhegazy mhegazy added Duplicate An existing issue was already created and removed Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Feb 8, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants