-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
FunctionComponent should allow returning VNode[] for HTM #3893
Comments
And just to be clear, I get the same behaviour using: import { h, FunctionComponent, render } from 'preact'
import htm from 'htm'
const html = htm.bind(h);
/** @type {FunctionComponent<{}>} */
const App = () => { // <-- tsserver gives the error on this line
return html`<div />`
} |
As |
@rschristian Can you link to articles describing why As of today, the preact typescript documentation has examples with I understand |
Check the "Why is React.FC not needed?" section here. It's an anti-pattern and has been for a few years now. Use type inference, there's absolutely no need to explicitly type components.
The TS docs on the Preact site are pretty out of date and rough unfortunately, and not a priority for me to fix at the moment. I wouldn't recommend you type events as it suggests either. |
Thanks, that makes sense! Would you accept a PR for the typescript documentation page (I should have some time to update that in the next couple of weeks), or is this part of a larger operation to be doen later? |
PRs definitely welcome, as far as I am aware there are no plans for future content changes (beyond maybe preactjs/preact-www#1098). |
Describe the bug
Trying to use typing (tsserver with JSDoc), with Preact/HTM, I get a type-mismatch when I try to annotate my Function Components:
To Reproduce
tsconfig.json
Expected behavior
Obviously no tsserver error.
I think that
FunctionComponent
is expecting jsx components (which only ever return a single parent node; whereas HTM can return an array of VNode's).The text was updated successfully, but these errors were encountered: