Skip to content

lib.d.ts: Nullable arguments for initMouseEvent() #11380

Closed

Description

While deprecated, the typings of MouseEvent.initMouseEvent() should still support strict null checks.

TypeScript Version: 2.0.3

Code

let event = document.createEvent('MouseEvent') as MouseEvent;

// Initialize the mouse event data.
event.initMouseEvent(
  'click', true, true, window, 0,
  0, 0,
  0, 0,
  false, false,
  false, false,
  0, null   // <--- Field `relatedTarget`. Error: null not accepted
);

Expected behavior:
MDN docs specify:

relatedTarget
the event's related EventTarget. Only used with some event types (e.g. mouseover and mouseout). In other cases, pass null.

So you would expect typing to read EventTarget | null.

Actual behavior:

Null not accepted with strict null checks on.

Not sure whether any of the other fields should accept null or undefined as well...

Activity

  1. vidartf commented on Oct 5, 2016

    @vidartf
    Author

    Workaround: Pass null!.

  2. added
    Domain: lib.d.ts
    Bug
    on Oct 6, 2016
  3. added this to the milestone on Oct 6, 2016
  4. mhegazy commented on Oct 6, 2016

    @mhegazy
    Contributor
  5. vidartf commented on Oct 6, 2016

    @vidartf
    Author
  6. modified the milestones: TypeScript 2.1, on Oct 12, 2016
  7. added
    Fixed in TSJS repo
    and removed on Oct 21, 2016
  8. modified the milestones: TypeScript 2.1, on Oct 27, 2016
  9. added
    Fixed
    and removed
    Fixed in TSJS repo
    on Oct 31, 2016
  10. locked and limited conversation to collaborators on Jun 19, 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

    BugDomain: lib.d.tsFixed

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions