-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
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
import React, { Component } from 'react';
type Props<T> = {
generate: (someArg: any) => T;
consume: (data: T) => React.ReactNode;
};
class Foo<T> extends Component<Props<T>> {}
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 `{}`
/>
);
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:
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created