Skip to content

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

@takeohman

Description

@takeohman

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.

Activity

added
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript
BugA bug in TypeScript
on Feb 13, 2015
added this to the TypeScript 1.6 milestone on Feb 14, 2015
self-assigned this
on Feb 14, 2015
gdcohan

gdcohan commented on Mar 31, 2015

@gdcohan

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

mhegazy

mhegazy commented on Mar 31, 2015

@mhegazy
Contributor

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

gdcohan

gdcohan commented on Mar 31, 2015

@gdcohan

great--thanks!

assigned and unassigned on Apr 7, 2015
added
FixedA PR has been merged for this issue
and removed
BugA bug in TypeScript
on Apr 17, 2015

1 remaining item

removed this from the TypeScript 1.6 milestone on Apr 17, 2015
NekR

NekR commented on Apr 28, 2015

@NekR

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

new CustomEvent('test');
mhegazy

mhegazy commented on Apr 28, 2015

@mhegazy
Contributor

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

NekR commented on Apr 28, 2015

@NekR

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

NekR

NekR commented on Apr 30, 2015

@NekR

@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

mhegazy commented on Apr 30, 2015

@mhegazy
Contributor

@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

NekR commented on Apr 30, 2015

@NekR

@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

mhegazy commented on Apr 30, 2015

@mhegazy
Contributor

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

NekR commented on Apr 30, 2015

@NekR

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

mhegazy commented on Apr 30, 2015

@mhegazy
Contributor

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.

locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueRevisitAn issue worth coming back to

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zhengbli@NekR@gdcohan@takeohman@danquirk

        Issue actions

          Type definition of CustomEvent constructor needs parameter(s). · Issue #2029 · microsoft/TypeScript