Typescript: Typescript does not support proper Touch constructor

Created on 16 May 2017  路  11Comments  路  Source: microsoft/TypeScript

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.

Bug lib.d.ts help wanted

All 11 comments

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;
}

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

```ts
declare var Touch: {
prototype: Touch;
new(): Touch;
}
````
There is now parameters in the constructor function

@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

@dblVs you wrote
```ts
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.

@olegdunkan ok, I edited to be more clear

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.

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

@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 ,

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhuravlikjb picture zhuravlikjb  路  3Comments

MartynasZilinskas picture MartynasZilinskas  路  3Comments

CyrusNajmabadi picture CyrusNajmabadi  路  3Comments

siddjain picture siddjain  路  3Comments

weswigham picture weswigham  路  3Comments