preact icon indicating copy to clipboard operation
preact copied to clipboard

Type 'VNode<any> | VNode<any>[]' is not assignable to type 'VNode<any> | null'

Open zim32 opened this issue 3 years ago • 0 comments

  • [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.

zim32 avatar Nov 24 '22 13:11 zim32