Preact: Preact + TypeScript won't allow me to directly call the h function instead of using JSX

Created on 24 Jun 2019  路  4Comments  路  Source: preactjs/preact

I'm using create-react-app for project setup.

I found that I can't directly use h function in TypeScript.

Please see this minimum example code:

import { FunctionalComponent, h } from 'preact';

const Text: FunctionalComponent = () => {
    const tag = 'div'
    const props = {}
    const children = 'I am children'

    return (
        h(tag, props, children)
    )
}

It says: Cannot invoke an expression whose type lacks a call signature. Type 'typeof h' has no compatible call signatures.

If I directly use JSX, it will be fine:

How can I directly use the h function in TypeScript?

related issue

Most helpful comment

@rockmandash 10.0.0-beta.3 should be the latest and the issue should be fixed there, could try upgrading and tell me if that solves your problem?

All 4 comments

What version of preact are you using?

@JoviDeCroock I'm using ^10.0.0-beta.2 version (latest beta version)

@rockmandash 10.0.0-beta.3 should be the latest and the issue should be fixed there, could try upgrading and tell me if that solves your problem?

It worked!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adriaanwm picture adriaanwm  路  3Comments

paulkatich picture paulkatich  路  3Comments

kossnocorp picture kossnocorp  路  3Comments

skaraman picture skaraman  路  3Comments

mizchi picture mizchi  路  3Comments