-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
regression in 5.4: error TS2604: JSX element type 'Cmp' does not have any construct or call signatures. #57862
Comments
Don't know how that label got added - I haven't gotten the chance to actually look at this issue. My apologies. |
@RyanCavanaugh yes but that error doesn't appear any more, only the 2604 one |
This is, for all intents and purposes, a correct error that was missed in 5.3. Prior versions were incorrectly (within the bounds of correct analysis that actually exist) allowing the call, though I'm still not exactly sure why. Further reduced (bisect on this one is still #56004): declare const React: any;
namespace JSX {
export interface IntrinsicElements {
div: {
name: string;
as?: "div";
};
}
}
// 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> = (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 & Record<any, any>>
: never
const Poly1 = <C extends string | FunctionComponent<unknown>>(thing: { as: C } & PropsOf<C>) => {
const Cmp = thing.as;
const p1 = <Cmp {...(null as any)} />;;
if (typeof Cmp === "string") {
const p2 = <Cmp {...(null as any)} />;
} else {
const p3 = <Cmp {...(null as any)} />;
}
}
Poly1({ as: "div", name: "foo" }); In 5.3, Correct analysis of this function basically boils down to being able to reason about the fact that Poly1<"baz">(...); can't actually happen since if C = |
I'm a bit lost - so you're saying that this polymorphic behavior should never have worked and cannot work? |
BTW in the original implementation if |
@RyanCavanaugh I'm not sure what to do here - is a polymorphic component impossible, or are we doing it wrongly? |
Ok - with some inspiration here I managed to make it pass in newer TS versions, will merge soon. Since I understand that it was failing correctly, I'll close this issue. |
Sorry for the delay btw, we were double-checking a few other things to make sure this wasn't secretly a bug of some kind. Glad to hear you got an acceptable solution on your end. |
π 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
In 5.3.3, the type of Cmp is roughly
String|FunctionComponent
, and in 5.4.2 it'sC|(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
The text was updated successfully, but these errors were encountered: