Skip to content
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

(event: TouchEvent) => void is not assignable "touchstart" event. #22565

Closed
Glinkis opened this issue Mar 14, 2018 · 7 comments · Fixed by microsoft/TypeScript-DOM-lib-generator#394
Assignees
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

@Glinkis
Copy link

Glinkis commented Mar 14, 2018

TypeScript Version: 2.8.0-dev.20180314

Code

const onTouchStart = (event: TouchEvent) {}
document.addEventListener("touchstart", onTouchStart);

Expected behavior:
onTouchStart should be treated as an event listener.

Actual behavior:

Argument of type '(event: TouchEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
  Type '(event: TouchEvent) => void' is not assignable to type 'EventListenerObject'.

Playground Link: link
Though the playground does not really demonstrate the issue, as it's not on the newest typescript version.

@RyanCavanaugh
Copy link
Member

Doesn't repro for me on latest. Are you passing any commandline flags as well?

@Glinkis
Copy link
Author

Glinkis commented Mar 14, 2018

No, just running it normally after updating to the latest @next.

@timocov
Copy link
Contributor

timocov commented Mar 23, 2018

@RyanCavanaugh

we have the same errors in our project with 2.8. Steps to reproduce is very simple:

  1. mkdir test && cd test
  2. npm install typescript@2.8-rc
  3. ./node_modules/.bin/tsc --init
  4. touch file.ts
  5. Insert the following code into file.ts:
    declare function onTouchStart(event: TouchEvent): void;
    document.addEventListener('touchstart', onTouchStart);
  6. ./node_modules/.bin/tsc

As result:

file.ts(2,41): error TS2345: Argument of type '(event: TouchEvent) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.
  Type '(event: TouchEvent) => void' is not assignable to type 'EventListenerObject'.
    Property 'handleEvent' is missing in type '(event: TouchEvent) => void'.

@MaceWindu
Copy link

MaceWindu commented Mar 26, 2018

The reason of it is that typing of touch events changed in lib.dom.d.ts from TouchEvent to Event.
by this commit: 67c7b36#diff-46fd87925e4552c166ec188712741c3f

@mhegazy mhegazy added 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 and removed Needs More Info The issue still hasn't been fully clarified labels Mar 26, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Mar 26, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 26, 2018

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.

@jakearchibald
Copy link

jakearchibald commented Mar 26, 2018

Created a PR microsoft/TypeScript-DOM-lib-generator#394.

This is a pretty big regression and it doesn't seem easy to work around. Feels like 2.8 shouldn't ship without a fix.

@mhegazy mhegazy self-assigned this Mar 27, 2018
@mhegazy mhegazy added the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Mar 27, 2018
@mhegazy mhegazy reopened this Mar 27, 2018
@timocov
Copy link
Contributor

timocov commented Mar 27, 2018

@mhegazy as soon it is already fixed in tsjs repo, is it possible to include it in 2.8.2?

@mhegazy mhegazy modified the milestones: TypeScript 2.9, TypeScript 2.8.2 Mar 27, 2018
@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 Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet labels Mar 28, 2018
@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 Mar 28, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 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

Successfully merging a pull request may close this issue.

6 participants