preact
preact copied to clipboard
Type 'VNode<any> | VNode<any>[]' is not assignable to type 'VNode<any> | null'
- [x ] Check if updating to the latest Preact version resolves the issue
Describe the bug When using htm with typescript I have types incompatibility
import {FunctionalComponent, h} from 'preact'
import htm from 'htm'
const html = htm.bind(h)
const TestComponent: FunctionalComponent<{ foo: number }> = ({ foo }) => {
return html`<div>${foo}</div>`
}
Here typescript complains that
TS2322: Type '({ foo }: RenderableProps<{ foo: number; }, any>) => VNode<any> | VNode<any>[]' is not assignable to type 'FunctionalComponent<{ foo: number; }>'. Type 'VNode<any> | VNode<any>[]' is not assignable to type 'VNode<any> | null'. Type 'VNode<any>[]' is missing the following properties from type 'VNode<any>': type, props, key
Expected behavior No type error.
Doing
return html`<div>${foo}</div>` as VNode<any>
resolves this issue but I think it will be better to change htm or FunctionalComponent declaration.