Skip to content

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

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

  1. added
    Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScript
    BugA bug in TypeScript
    on Feb 13, 2015
  2. 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?

  3. mhegazy commented on Mar 31, 2015

    @mhegazy
    Contributor

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

  4. gdcohan commented on Mar 31, 2015

    @gdcohan

    great--thanks!

  5. added
    FixedA PR has been merged for this issue
    and removed
    BugA bug in TypeScript
    on Apr 17, 2015
  6. 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');
  7. 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

  8. NekR commented on Apr 28, 2015

    @NekR

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

  9. NekR commented on Apr 30, 2015

    @NekR

    Mohamed Hegazy (@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.

  10. mhegazy commented on Apr 30, 2015

    @mhegazy
    Contributor

    Arthur Stolyar (@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.

  11. NekR commented on Apr 30, 2015

    @NekR

    Mohamed Hegazy (@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.

  12. 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);
  13. 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.

  14. mhegazy commented on Apr 30, 2015

    @mhegazy
    Contributor

    Thanks Arthur Stolyar (@NekR). Zhengbo Li (@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.

  15. 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

      Issue actions