Skip to content

Missing error after spreading generic props into JSX #29509

Description

TypeScript Version: 3.2.2

Search Terms:

Code

typeComponent<P>=(props: P)=>any;constmyHof=<ComposedComponentPropsextendsany>(ComposedComponent: Component<ComposedComponentProps>,)=>{typeWrapperComponentProps=ComposedComponentProps&{myProp: string};declareconstWrapperComponent: Component<WrapperComponentProps>;declareconstprops: ComposedComponentProps;// Expected no error, got none - goodWrapperComponent({ ...props,myProp: '1000000'});// Expected error, got one - goodWrapperComponent({ ...props,myProp: 1000000});}

However, when I try to do the same with React (.tsx):

importReactfrom'react';constmyHoc=<ComposedComponentPropsextendsany>(ComposedComponent: React.ComponentClass<ComposedComponentProps>,)=>{typeWrapperComponentProps=ComposedComponentProps&{myProp: string};declareconstWrapperComponent: React.ComponentClass<WrapperComponentProps>;declareconstprops: ComposedComponentProps;// Expected no error, got none - good<WrapperComponent{...props}myProp={'1000000'}/>;// Expected error, but got none - bad!<WrapperComponent{...props}myProp={1000000}/>;};

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions