Skip to content

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

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

Closed
vidartf opened this issue Oct 5, 2016 · 3 comments
Closed

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

vidartf opened this issue Oct 5, 2016 · 3 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 Help Wanted You can do this

Comments

@vidartf
Copy link

vidartf commented Oct 5, 2016

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

@vidartf
Copy link
Author

vidartf commented Oct 5, 2016

Workaround: Pass null!.

@mhegazy mhegazy added Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Bug A bug in TypeScript labels Oct 6, 2016
@mhegazy mhegazy added this to the Community milestone Oct 6, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Oct 6, 2016

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@vidartf
Copy link
Author

vidartf commented Oct 6, 2016

@mhegazy mhegazy modified the milestones: TypeScript 2.1, Community Oct 12, 2016
@mhegazy mhegazy added Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet and removed Fixed in TSJS repo labels Oct 21, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.1, TypeScript 2.1.2 Oct 27, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet labels Oct 31, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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 Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

3 participants