-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JSX generic types that are themselves props are being incorrectly inferred in TS@next #28394
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
DefinitelyTyped/DefinitelyTyped#30331 (comment) It seems that the condition for it to happen is that the generic parameter needs to itself be used as part of the props; not as the value of some of the props, but as props themselves. class FieldArray<P = {}> extends Component<(...) & Partial<P>> export type ButtonProps<T = {}> = (...) & T |
Whew, so this turned out to be an effect from an enhancement to inference we made (#28006). Specifically, prior to #28006 inference would fail at the reported locations, fall back to Quite simply, we want to force the distribution during reverse-mapped-property inference, since it may expose more of the type variables we're looking for directly to the inference engine. It is safe to do so, since despite the |
I've opened #28421 to track the behavior of intersecting |
TypeScript Version: 3.2.0-dev.20181107
Search Terms: I was told to make an issue 🤷♀️
Code
This is something I encountered while working on DefinitelyTyped/DefinitelyTyped#30331; there are at least two instances of generics that are incorrectly inferred on TS@next.
It seems the compiler is overly eager to add things to the generic parameter that are not actually necessary, with incomplete types (they're just
{}
) and thus they end up causing errors instead. For example,is inferring
FieldArray
asFieldArray<{ name: {}; component: {} }>
even thoughname
andcomponent
are already present inFieldArray<{}>
; this in turn causesMyArrayField
to be expected to receive{ name: {}; component: {} }
as props, while it only receives{}
.A similar issue happened with
<Button {...props}/>
in the reactstrap test, see comment chain. The spread ofprops
causedButton
to basically infer its own props as being& Record<keyof props, {}>
, which more obviously broke the type ofchildren
.The text was updated successfully, but these errors were encountered: