Closed
Description
π 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
π» 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
Labels
No labels