Skip to content

JSX generic types that are themselves props are being incorrectly inferred in TS@nextΒ #28394

Closed
@Jessidhia

Description

@Jessidhia

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,

                            <FieldArray
                                name="field9"
                                component={ MyArrayField }
                            />

is inferring FieldArray as FieldArray<{ name: {}; component: {} }> even though name and component are already present in FieldArray<{}>; this in turn causes MyArrayField 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 of props caused Button to basically infer its own props as being & Record<keyof props, {}>, which more obviously broke the type of children.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions