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

Type definition of CustomEvent constructor needs parameter(s). #2029

Closed
takeohman opened this issue Feb 13, 2015 · 12 comments
Closed

Type definition of CustomEvent constructor needs parameter(s). #2029

takeohman opened this issue Feb 13, 2015 · 12 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Revisit An issue worth coming back to

Comments

@takeohman
Copy link

Type definition of CustomEvent constructor needs at least one parameter.
(The constructor of Event class also needs one parameter, actually.)

Since the current definition has no parameter, I encountered an error when I run a generated JS code by
Jasmine with node.

Following links are about CustomEvent class .
https://dom.spec.whatwg.org/#interface-customevent
https://developer.mozilla.org/en/docs/Web/API/CustomEvent

http://html5index.org/DOM%20-%20EventInit.html
http://html5index.org/DOM%20-%20CustomEventInit.html

I wrongly send a pull request #2007 on this issue.
Sorry about that.

@danquirk danquirk added Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Bug A bug in TypeScript labels Feb 13, 2015
@mhegazy mhegazy added this to the TypeScript 1.6 milestone Feb 14, 2015
@mhegazy mhegazy self-assigned this Feb 14, 2015
@mhegazy mhegazy added the Revisit An issue worth coming back to label Mar 24, 2015
@gdcohan
Copy link

gdcohan commented Mar 31, 2015

It looks like the Event constructor has the same issue--should I file a separate ticket on that?

@mhegazy
Copy link
Contributor

mhegazy commented Mar 31, 2015

@zhengbli is working on an updated library typings. I believe this should be handled by his change. so stay tuned.

@gdcohan
Copy link

gdcohan commented Mar 31, 2015

great--thanks!

@mhegazy mhegazy assigned zhengbli and unassigned mhegazy Apr 7, 2015
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Bug A bug in TypeScript labels Apr 17, 2015
@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 17, 2015
@mhegazy mhegazy closed this as completed Apr 17, 2015
@NekR
Copy link

NekR commented Apr 28, 2015

Is it in 1.5 alpha already? Because I cannot instance CustomEvent or even Event, this does not works:

new CustomEvent('test');

@mhegazy
Copy link
Contributor

mhegazy commented Apr 28, 2015

This was not in 1.5-alpha but should be in the next release. you can find the updated lib.d.ts in https://github.com/Microsoft/TypeScript/blob/release-1.5/bin/lib.dom.d.ts

@NekR
Copy link

NekR commented Apr 28, 2015

Yep, thank you! I just wondered if it was already in alpha.

@NekR
Copy link

NekR commented Apr 30, 2015

@mhegazy

Hmm.. just updated to beta version now I cannot use DateView or invoke initCustomEvent on CustomEvent because it says what it's just Event. I know I can download all these .d.ts files manually, but this does not seems right anyway.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 30, 2015

@NekR sorry about that. The issue is fixed in master, but did not make it in time for the beta. see #2953 for more details. it should be fixed in the next release. As a work around for now, you can copy the definitions of DataView from https://github.com/Microsoft/TypeScript/blob/master/src/lib/extensions.d.ts#L48 locally.

@NekR
Copy link

NekR commented Apr 30, 2015

@mhegazy I will copy it, thanks! But what about initCustomEvent, is it fixed in master? I mean, for now of course I will use CustomEvent since it's now exists with correct definition, but there are environments which do not supports CustomEvent it requires initCustomEvent to be used.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 30, 2015

I am not sure i understand the issue with CustomEvent, this works file for me:

var c: CustomEvent;
c.initCustomEvent("custom", true, false, undefined);

@NekR
Copy link

NekR commented Apr 30, 2015

This:

var event = document.createEvent('CustomEvent');
event.initCustomEvent('test', true, true, void 0);
this.node.dispatchEvent(event);

produces this error:
error TS2339: Property 'initCustomEvent' does not exist on type 'Event'.

This:

var event:CustomEvent = document.createEvent('CustomEvent');
event.initCustomEvent('test', true, true, void 0);
this.node.dispatchEvent(event);

produces this error:
error TS2322: Type 'Event' is not assignable to type 'CustomEvent'. Property 'detail' is missing in type 'Event'.

And only casting works:

var event = <CustomEvent>document.createEvent('CustomEvent');
event.initCustomEvent('test', true, true, void 0);
this.node.dispatchEvent(event);

First case worked just fine 30 mins2 hours ago when I was on TS1.5-Alpha.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 30, 2015

Thanks @NekR. @zhengbli is fixing this now. we should have a working lib.d.ts for you to try soon. I have logged a different issue for is under #2975.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Revisit An issue worth coming back to
Projects
None yet
Development

No branches or pull requests

6 participants