Skip to content

DragEventInit not declared in lib.dom.d.ts #26441

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
kpaxton opened this issue Aug 14, 2018 · 3 comments
Closed

DragEventInit not declared in lib.dom.d.ts #26441

kpaxton opened this issue Aug 14, 2018 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@kpaxton
Copy link

kpaxton commented Aug 14, 2018

TypeScript Version: 2.9.2

Search Terms: DragEventInit, drag event init

Code

export class DragEventMock {
 static mockDragEvent(
    eventType: 'drag'|'dragend'|'dragenter'|'dragexit'|'dragleave'|'dragover'|'dragstart'|'drop',
    dataTransfer: DataTransfer = new DataTransfer()
 ): DragEvent {
  const event = new DragEvent(eventType, {
    layerX: 0,
    layerY: 0,
    dataTransfer: dataTransfer
  });
  return event;
 }
}

Expected behavior:
compiles correctly.
Does not give an error in IDE (VSCode)
I also feel I should be able to specify as DragEventInit to solve this issue as well.

Actual behavior:

error TS2345: Argument of type '{layerX: number; layerY: number; dataTransfer: DataTransfer; }' is not assignable to parameter of type '{dataTransfer?: DataTransfer;}'.
Object literal may only specify known properties, and 'layerX' does not exist in type '{dataTransfer?: DataTransfer;}'.

Playground Link: http://www.typescriptlang.org/play/index.html#src=export%20class%20DragEventMock%20%7B%0D%0A%20%20%20%20static%20mockDragEvent(%0D%0A%20%20%20%20%20%20%20%20eventType%3A%20'drag'%7C'dragend'%7C'dragenter'%7C'dragexit'%7C'dragleave'%7C'dragover'%7C'dragstart'%7C'drop'%2C%0D%0A%20%20%20%20%20%20%20%20dataTransfer%3A%20DataTransfer%20%3D%20new%20DataTransfer()%0D%0A%20%20%20%20)%3A%20DragEvent%20%7B%0D%0A%20%20%20%20%20%20%20%20const%20event%20%3D%20new%20DragEvent(eventType%2C%20%7B%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20layerX%3A%200%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20layerY%3A%200%2C%0D%0A%20%20%20%20%20%20%20%20%20%20%20%20dataTransfer%3A%20dataTransfer%0D%0A%20%20%20%20%20%20%20%20%7D)%3B%0D%0A%0D%0A%20%20%20%20%20%20%20%20return%20event%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0ADragEventMock.mockDragEvent('drag'%2C%20new%20DataTransfer())%3B%0D%0A

Related Issues:

Should just be able to add to the lib.dom.d.ts file

declare type DragEventType = 'drag'|'dragend'|'dragenter'|'dragexit'|'dragleave'|'dragover'|'dragstart'|'drop'
declare interface DragEventInit extends MouseEventInit {
    dataTransfer?: DataTransfer;
}

And then update:

declare var DragEvent: {
    prototype: DragEvent;
    new(type: DragEventType, dragEventInit?: DragEventInit): DragEvent;
}
@kpaxton
Copy link
Author

kpaxton commented Aug 14, 2018

Looks like upon further digging, in /src/lib/dom.generated.d.ts this fix is already present. However it is not reflected in the /lib/lib.dom.d.ts.

I also checked [email protected] and still do not see it in the lib.dom.d.ts.

@RyanCavanaugh
Copy link
Member

Duplicate #17885 ?

@kpaxton
Copy link
Author

kpaxton commented Aug 15, 2018

@RyanCavanaugh yea looks like it. Not sure why it didn't come up in my searches.

I do wonder why the lib.dom.d.ts hasn't updated yet though considering the dom.generated.d.ts has it in there properly?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants