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

[TypeScript] GestureEvent Callbacks Aren't Supported In Strict Mode #28

Open
orangecoloured opened this issue Sep 30, 2022 · 7 comments

Comments

@orangecoloured
Copy link

Sorry I use issues for this kind of questions.

Do I understand correctly that I need to use CustomEvent<GestureEventData> for the handler functions?
And if so, what do I do with the addEventListener call type errors? It expects to have Event for the event parameter, but gets CustomEvent<GestureEventData>. Is there a wrapping function that could avoid this type conflict or am I missing something?
Should I use some workarounds to make TS linter happy?

@SE2Dev
Copy link
Collaborator

SE2Dev commented Sep 30, 2022

What linter are you using?

This should not produce any warnings or errors:

import type { GestureEventData } from "contactjs";

const element = document.getElementById("targetElement") as HTMLElement;

element.addEventListener("panstart", (e: CustomEvent<GestureEventData>) => {
	console.log(e);
});

Technically speaking, the following is preferred but the types are slightly still borked in v2.1.0:

import type { GestureEvent } from "contactjs";

const element = document.getElementById("targetElement") as HTMLElement;

element.addEventListener("panstart", (e: GestureEvent) => {
	console.log(e);
});

@orangecoloured
Copy link
Author

I'm using preact setup with eslint 8.24
The error is Type 'Event' is missing the following properties from type 'CustomEvent<GestureEventData>': detail, initCustomEvent

@biodiv
Copy link
Owner

biodiv commented Sep 30, 2022

I just released v2.1.1 which includes 737fbca

@SE2Dev
Copy link
Collaborator

SE2Dev commented Sep 30, 2022

@orangecoloured I'd recommend trying the second solution using v2.1.1, if it still doesn't work can you let me know what version of TypeScript you're using?

@orangecoloured
Copy link
Author

orangecoloured commented Sep 30, 2022

@SE2Dev
Screenshot 2022-09-30 at 5 09 46 PM

TS version is 4.8.4

@SE2Dev
Copy link
Collaborator

SE2Dev commented Sep 30, 2022

I managed to reproduce your issue, it requires "strict": true in the tsconfig.json. I'll let you know when we have a fix available.

Discussions for possible resolutions are here.

@SE2Dev SE2Dev changed the title TypeScript question [TypeScript] GestureEvent Callbacks Aren't Supported In Strict Mode Sep 30, 2022
@SE2Dev
Copy link
Collaborator

SE2Dev commented Sep 30, 2022

For the time being I recommend the following as a workaround:

import type { GestureEvent } from "contactjs";

const element = document.getElementById("targetElement") as HTMLElement;

element.addEventListener("panstart", (e) => {
    const event = e as GestureEvent;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants