Skip to content

regression in 5.4: error TS2604: JSX element type 'Cmp' does not have any construct or call signatures.Β #57862

Closed
@wmertens

Description

@wmertens

πŸ”Ž Search Terms

TS2604

πŸ•— Version & Regression Information

This is a regression, it started happening with 5.4.0

Note that that comment lists 2 issues, now there's only the one TS2604 issue.

The issue still exists in @next.

⏯ Playground Link

https://www.typescriptlang.org/play?#code/PTAEEsBcHIGdQIoHdwGtQCMCulQHtUBYAKHAFsAHPAJ1wCUBTAQwGNcAzavM0aa5ttBIkQoACoALcPGmh+ARyzh+AE1DsaoSBIYRYsLAwA0oFhKYA7AObhrEXJDxyGkLNQvjQZJqgYzcTKAq4OzsDPwWuOFc1CSQAJ4UugDyGABWDGwAClwUsAA8YgB8oAC8JKCVngwAHpAMFirwjCw0KvmW8SadRRVVAPzifZUAXKAWDABu4QDcwsQJSaAAYlgWbOB4FgDC3FQTkflZZaBrqBZ4SBYlpaAAFBS5sGNZAJRlJZ1zxCJgsJDUWxWAA+7A8sgUSlU6k02l00gMxlM5msQPsWicWwANvFkZl0BpqOoPN5fP5QIFgqFwg0otQYnFErocng8sl2PltskALJZG6gLm80C1eqNeC+eJ4digABSAGUABoAOgAkpFARZYOAWABRLEMMi02DDUCDeXKtUA2xa3X6w2RWAAbUFWQAuiaxi7hXUGk0VmsNltdpQtrT8rYwkTkoCrCy8r1iFVTaBUhlsk98tHwLGngmk2MJtNYj9iK1NbgsngcWUTZzvaK-f8NVZQMD-etIJsdntQ5ETk20W3Vh2u8H9rSincAN4mpNMZ4CygnaDBSbQCnwbZGWdVJV7x6s42JqoAXzGU43-U9oBPoAAZKA47B2fkB3YRb7N8mV+A16BPUU7ylCUM7HkmlSiJIsjBCoFjQHSMQQB4ACsSoAMzoZgODCvSNAyChSoACxKgADDulT8K47igJyS5TnuSoHnkJ5FFI+TANslBFN84FVKI4EAHr9CaJ7zEAA

πŸ’» Code

// it's Qwik but ok
import React from 'react'

// This is required for the issue, changing it to return T makes it a different error
type ObjectProps<T> =
    T extends Record<any, any>
    ? T
    : never;

type FunctionComponent<P = unknown> = (props: P) => any;

// string|fn is required for the issue, changing it to only check for fn makes it a different error
type PropsOf<COMP> = COMP extends keyof JSX.IntrinsicElements
    ? JSX.IntrinsicElements[COMP]
    : COMP extends FunctionComponent<infer OrigProps>
    ? ObjectProps<OrigProps>
    : never

const Poly =
    <C extends string | FunctionComponent = string | FunctionComponent>({
        as: Cmp = 'div' as C,
        ...props
    }: { as?: C } & PropsOf<string extends C ? 'div' : C>) => {
        // This didn't error in 5.3.3 but errors in 5.4.0
        return <Cmp {...props}>hi</Cmp>;
        //      ^?
    }

In 5.3.3, the type of Cmp is roughly String|FunctionComponent, and in 5.4.2 it's C|(C&string)

πŸ™ Actual behavior

It can't determine that Cmp is a function

πŸ™‚ Expected behavior

It should determine that Cmp is a valid JSX tag

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions