-
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
Type inference failing on JSX generics - works fine in a function call #23412
Comments
@NicholasBoll What's the type of
Shouldn't it be:
? |
@lucasbasquerotto |
@NicholasBoll I understand. So, about your problem, you have:
The type You could try:
Although it doesn't give an error with If I write a wrong property the error is shown correctly, but if I place the cursor above a correct property it shows |
@lucasbasquerotto Exactly. I updated the example above to use Here's another example that is similar that shows the problem as well: declare function Select<T>(props: {
options: T[],
render: (item: T) => JSX.Element
}): JSX.Element
<Select
options={[{
foo: 'bar',
}, {
foo: 'baz'
}]}
render={item => {
item // T instead of { foo: string }
item.foo // any
return <div>{item.foo}</div>
}}
/>
Select({
options:[{
foo: 'bar',
}, {
foo: 'baz'
}],
render: item => {
item // { foo: string }
item.foo // string
return <div>{item.foo}</div>
}
}) |
The |
@weswigham do you know what is going on here? |
The key comment in the OP:
This is a duplicate of #22636. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.7.2, 2.7.2-dev.20180207, 2.7.2-insiders.20180209, 2.8.0, 2.8.1
Search Terms: JSX, Inference, React
Code
tsconfig.json
Expected behavior:
slice
type in therender
function isstring
Actual behavior:
slice
type in therender
function isSlice
Playground Link: Playground doesn't support JSX
Related Issues:
Additional Notes:
I narrowed it down to breaking between 2.7.1 and 2.7.2. I tried multiple versions under 2.7.1 down to 2.5.3 and they all worked as expected.
Type checking works. Both throw an error accessing
slice.foo
, but when mousing overslice
in the JSX example says 'Slice' and a valid property access gives a type ofany
I didn't really know how to classify this bug. Feel free to change the title if it doesn't make sense
The text was updated successfully, but these errors were encountered: