Skip to content
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

Missing error after spreading generic props into JSX #29509

Closed
OliverJAsh opened this issue Jan 21, 2019 · 4 comments · Fixed by #29571
Closed

Missing error after spreading generic props into JSX #29509

OliverJAsh opened this issue Jan 21, 2019 · 4 comments · Fixed by #29571
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@OliverJAsh
Copy link
Contributor

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} />;
};
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jan 23, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.4.0 milestone Jan 23, 2019
@weswigham
Copy link
Member

weswigham commented Jan 24, 2019

Looks like the issue is caused by the extends any. As a workaround, use extends unknown (to which it should behave identically to) until we have a fix in, instead.

@OliverJAsh
Copy link
Contributor Author

Aha, thanks. The reason I do the extends btw is because it's needed for arrow functions in .jsx/.tsx.

@weswigham
Copy link
Member

weswigham commented Jan 24, 2019

@OliverJAsh A trailing comma on the type argument list should disambiguate as well.

@RyanCavanaugh
Copy link
Member

@weswigham let's please merge at the start of the 3.9 branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants