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

Global variable event: Event in lib.es6.d.ts #11583

Closed
sod opened this issue Oct 13, 2016 · 6 comments · Fixed by microsoft/TypeScript-DOM-lib-generator#159
Closed

Global variable event: Event in lib.es6.d.ts #11583

sod opened this issue Oct 13, 2016 · 6 comments · Fixed by microsoft/TypeScript-DOM-lib-generator#159
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@sod
Copy link

sod commented Oct 13, 2016

TypeScript Version: 2.0.3

Code

tsconfig.json includes lib es6:

{
    "compilerOptions": {
        "lib": [
            "es6",
            "dom"
        ]
    },
}
function eventHandler() {
    // typescript doesn't complain about missing event variable, because event is declared as global in lib.es6.d.ts
    console.log(event.target);
}

Expected behavior:

Don't expect event to exist on the global object. Couldn't reproduce it in Safari, Firefox or Chrome. It's always console.log(window.event); // undefined

Actual behavior:

event: Event is declared as global variable in lib.es6.d.ts
https://github.com/Microsoft/TypeScript/blob/2e7c83abc833534181d97c534bfac865cd93b1f0/lib/lib.es6.d.ts#L18680
https://github.com/Microsoft/TypeScript/blob/2e7c83abc833534181d97c534bfac865cd93b1f0/lib/lib.es6.d.ts#L20129

@kitsonk
Copy link
Contributor

kitsonk commented Oct 13, 2016

According to MDN it is non-standard IE/Edge property. The typings for the lib are derived from the Edge IDL, which is likely that caused it to be there.

But it does seem to be present in other browsers (I checked Chrome)

'event' in window; // returns `true`
'foo' in window; // returns `false`

I guess it should be properly typed as Event | undefined.

@sod
Copy link
Author

sod commented Oct 13, 2016

Indeed. You are right. The property exists on window. But it is undefined, even in Edge 13 & IE 11.

image

So maybe declare var event: undefined, without the Event.

Edit: @kitsonk ah, it's filled while event listeners are executed in IE/edge. Hm

@kitsonk
Copy link
Contributor

kitsonk commented Oct 13, 2016

Yes, sorry, I meant to say that.

I suspect that IE/Edge continues to support it, though it isn't part of standards, and other browsers define it, but keep its value always undefined to avoid breaking lots of bad code, that running in strict mode, might cause an exception.

Anyways, I still suspect it is better to have it as Event | undefined.

@mhegazy mhegazy added Suggestion An idea for TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Oct 13, 2016
@mhegazy mhegazy added this to the Community milestone Oct 13, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Oct 13, 2016

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@jarrydfillmore
Copy link

Awesome!

@alisabzevari
Copy link
Contributor

I will do it 😄

@mhegazy mhegazy modified the milestones: TypeScript 2.1, Community Oct 17, 2016
@mhegazy mhegazy reopened this Oct 17, 2016
@mhegazy mhegazy added Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet and removed Fixed in TSJS repo labels Oct 21, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.1, TypeScript 2.1.2 Oct 27, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet labels Oct 31, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants