Skip to content

Typescript does not support proper Touch constructor #15874

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
dblVs opened this issue May 16, 2017 · 12 comments
Closed

Typescript does not support proper Touch constructor #15874

dblVs opened this issue May 16, 2017 · 12 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@dblVs
Copy link

dblVs commented May 16, 2017

Typescript does not support the valid Touch constructor

TypeScript Version: 2.3.1

Code

const a = new Touch({
  identifier: 2,
  target: document.body
})

Expected behavior:
It should not error because this is the valid constructor for Touch.
Actual behavior:
Errors since the constructor for Touch does not accept any parameters.

@dblVs
Copy link
Author

dblVs commented May 16, 2017

It should be:

declare var Touch: {
    prototype: Touch;
    new(touchInit: { 
       target: HTMLElement, 
       identifier: number,
       clientX?: number,
       clientY?: number,
       screenY?: number,
       screenX?: number,
       pageY?: number,
       pageX?: number,
       radiusX?: number,
       radiusY?: number,
       rotationAngle?: number,
       force?: number
     }): Touch;
}

@olegdunkan
Copy link

olegdunkan commented May 16, 2017

Check it https://github.com/Microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L11773

declare var Touch: {
    prototype: Touch;
    new(): Touch;
}

There is now parameters in the constructor function

@dblVs
Copy link
Author

dblVs commented May 16, 2017

@olegdunkan I'm sorry, I don't understand you. new(): Touch is not valid as you cannot do new Touch() to create a new one you need and initialisation object with properties target and identifier.

If you meant that that the constructor includes params, I cannot see them.

https://developer.mozilla.org/en-US/docs/Web/API/Touch/Touch

@olegdunkan
Copy link

@dblVs you wrote

declare var Touch: {
    prototype: Touch;
    new(touchInit: { 
       target: HTMLElement, 
       identifier: number,
       clientX?: number,
       clientY?: number,
       screenY?: number,
       screenX?: number,
       pageY?: number,
       pageX?: number,
       radiusX?: number,
       radiusY?: number,
       rotationAngle?: number,
       force?: number
     }): Touch;
}

It has got me confused because it doesn't match what I see in current lib.dom.d.ts.
You are right it have to be implemented. Sorry.

@dblVs
Copy link
Author

dblVs commented May 16, 2017

@olegdunkan ok, I edited to be more clear

@mhegazy
Copy link
Contributor

mhegazy commented May 16, 2017

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.

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

VarLong commented Jun 26, 2017

@dblVs 👍 ,
have you fix the issue? i want creat a touchevent , but the property is read-only,

@VarLong
Copy link

VarLong commented Jun 26, 2017

@mhegazy

i want to creat a touchEvent , but the constructor need a parametertouch.
const touchEvent = new TouchEvent("touchstart", {
touches: [touch],
targetTouches: [touch],
changedTouches: [touch]
});
.but the constructor of Touch do not need any parameter .

let touch = new Touch();

but i need pageX and pageY ,

@dblVs
Copy link
Author

dblVs commented Jun 26, 2017

@VarLong I guess I'll add it soon. I didn't do anything on it, but I will these days when i get time.

@saschanaz
Copy link
Contributor

Has been fixed by microsoft/TypeScript-DOM-lib-generator#415

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@mbest
Copy link
Member

mbest commented Jul 23, 2019

I see that this has been fixed in #24850, but my project is stuck on a 2.x version of TypeScript. How can I use new Touch({...}) without an error?

Edit: using new (Touch as any) works.

@jakebailey
Copy link
Member

Just looking at old issues; this has been fixed in lib for a good while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

8 participants