Wrong component's attribute type for preact project
Hello!
According to documentation preact emits regular DOM events (https://preactjs.com/guide/v10/typescript/#typing-events).
Let's take a look at the <button/> element and try to see what type of onClick attribute it has:
We can see that autocompletion suggestions are wrong because MouseEventHandler<HTMLButtonElement> looks like react type (it has generic), but the original DOM event handler for the onClick button has no generic type:
Please sign in to leave a comment.
To provide code assistance for props in JSX context, the IDE uses react type definitions stubs. It's the same in VSCode, for example:
Preact has own typings, but generics are used there as well:
onClick?: MouseEventHandler<Target> | undefined;
Thank you for answering so quickly!
Yes, you are right and generics are used as well in preact within h.JSXInternal.MouseEventHandler<HTMLButtonElement> - that is preact package, but the main problem remains the same - type is wrong.
Let me clarify your example, I have asked you about typescript and if we look at vscode again in the typescript context we will see that it suggests correct types:
So vscode understands that we're in a preact context and should use other dom event types because typescript language server helps it, but Intellij code model does not.
Yes, Intellij can temporarily request the help of a typescript server and tell us the correct type in tooltips, for example:
But Intellij code model can't do the same thing. Is this a known issue or you have some workarounds?
Ok, I see your point; please vote for https://youtrack.jetbrains.com/issue/WEB-59748/In-preact-projects-preact-typings-are-not-used-for-regular-DOM-attributes-resolving to get notified on any progress with it
Thank you for your help)