Skip to content

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

Closed
@vidartf

Description

@vidartf

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

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 issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions