Wrong component's attribute type for preact project


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:


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:

// MouseEvents
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?


Thank you for your help)


Please sign in to leave a comment.