Skip to content

Missing error after spreading generic props into JSX #29509

Closed
@OliverJAsh

Description

@OliverJAsh

TypeScript Version: 3.2.2

Search Terms:

Code

type Component<P> = (props: P) => any;

const myHof = <ComposedComponentProps extends any>(
    ComposedComponent: Component<ComposedComponentProps>,
) => {
    type WrapperComponentProps = ComposedComponentProps & { myProp: string };
    declare const WrapperComponent: Component<WrapperComponentProps>;

    declare const props: ComposedComponentProps;

    // Expected no error, got none - good
    WrapperComponent({ ...props, myProp: '1000000' });
    // Expected error, got one - good
    WrapperComponent({ ...props, myProp: 1000000 });
}

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

import React from 'react';

const myHoc = <ComposedComponentProps extends any>(
    ComposedComponent: React.ComponentClass<ComposedComponentProps>,
) => {
    type WrapperComponentProps = ComposedComponentProps & { myProp: string };
    declare const WrapperComponent: React.ComponentClass<WrapperComponentProps>;

    declare const props: ComposedComponentProps;

    // Expected no error, got none - good
    <WrapperComponent {...props} myProp={'1000000'} />;
    // Expected error, but got none - bad!
    <WrapperComponent {...props} myProp={1000000} />;
};

Metadata

Metadata

Assignees

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