-
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
Generic JSX Inference Issue #27411
Comments
Same root cause as #25826 |
Is this to be closed then? Not that I would want that, but that was the fate of the root issue. |
For this simple type of component, is there a workaround I could do? Not sure where I could annotate to help out TS. One problem is that this kind of component is used in conjunction with const ConnectedComponent = connect</*inferred generics*/>(/*...*/)(Foo) And thus the (Sorry if that use case is confusing--might be especially confusing if you don't use React+Redux) |
I seem to have solved the issue by moving the inline function definition into a variable like:
Can anyone confirm that this works for their use case? |
Those kinds of declarations (ie, lambdas without annotations or context) will issue errors under |
Yes sorry I should have clarified -- take either prop out and annotate and it works fine |
@mikeb-simspace Yes--Annotating const fine = (
<Foo
generate={() => 123}
consume={num => num / 2} // Works fine. Inferred type is `number`
/>
)
const error = (
<Foo
generate={thisCausesIssues => 123}
consume={num => num / 2} // Error! Inferred type of `num` is `{}`
/>
)
const noError = (
<Foo
generate={(noIssues: string) => 123}
consume={num => num / 2} // Works fine!
/>
) |
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed for automatic house-keeping purposes. |
Tried finding an issue for this, but nothing turned up. I'm getting unexpected behavior with generic JSX:
TypeScript Version: 3.1.1
Search Terms: generic jsx inference
Code
Expected behavior:
num
would infer correctly.Actual behavior:
num
is widened to the{}
type. On TS 3.1.1 I get the error above. On ts@next, it seems not to understand my props whatsoever.Playground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: