-
Notifications
You must be signed in to change notification settings - Fork 12.8k
5.0: Narrowing from type-guards ignored when constructing JSX call (2604) #53178
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
Comments
Duplicate #52232 |
The linked issue repros in 4.9.4 while mine does not. Could you clarify why you think it is a duplicate? |
I believe the root cause here - |
So if it turns out to root cause is a dupe, you won't consider this a 5.0 regression even though it only started failing when going from 4.9 to 5.0? |
Bisected to #52282 |
JSX function signatures are now detected as `any` in some projects such as https://github.com/alveshelio/solidjs-previewjs. This looks like it could be related to microsoft/TypeScript#53178
Right, this is basically the converse report of #50916 |
I'm not following the labelling here. It's considered a duplicate of an issue that was closed by the PR that caused it? Sounds more like you're saying this is intended behavior? |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
I'm also having a hard time trying to follow the thread here... I still have this issue on 5.0.3. Are we waiting on a change in @types/react then? Or is this supposed to be fixed already? |
This issue unfortunately isn't fixed! I'm still getting errors in Typescript 5.1.6. (I'm pretty sure this is the same issue.) Here is a playground showing the error. The problem is that |
Just a note: it works when u "forward" the type Foo = {
bar: string;
}
// Stub of ReactElement:
interface ReactElement<P = any> {
props: P;
}
declare function isValidElement<P>(object: {} | null | undefined): object is ReactElement<P>
function doSomething<P>(input: Foo | ReactElement<P>) {
if (isValidElement(input)) {
return input;
}
// Type should be narrowed, and it is
return input.bar;
} |
an easy fix for the problem is to not use just ReactElement but |
Bug Report
🔎 Search Terms
does not have any construct or call signatures.(2604)
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
We saw 8 errors in our codebase pop up. This might be a fairly common issue in React Native codebases or any codebase having types like
React.ComponentType<any> | React.ReactElement
.Note that this works either with either
which requires a change in
@types/react-native
or
which requires a change in
@types/react
.The change in
@types/react-native
makes more sense but means other type libraries need to update as well.3rd option is making
React.ReactElement
default toReact.ReactElement<unkown>
instead ofReact.ReactElement<any>
but that might be even more disruptive.I'll fiddle with each alternative but I would appreciate if you could check if this new behavior in TypeScript is so valueable to warrant this breakage in the ecosystem.
🙁 Actual behavior
JSX element type 'ListHeaderComponent' does not have any construct or call signatures.(2604)
🙂 Expected behavior
No type error since
isValidElement
narrows toReact.ReactElement
i.e. the else branch should just beReact.ComponentType<any>
The text was updated successfully, but these errors were encountered: