Skip to content

Generic JSX components #15742

Closed
Closed
@mhegazy

Description

@mhegazy

The fix in #15687 did not get the original issue resolved, now that we have the apparent type, we can not spread T into a Component<T>.

here are a few samples:

import * as React from "react";

const decorator = function <T>(Component: React.StatelessComponent<T>): React.StatelessComponent<T> {
    return (props) => <Component {...props} ></Component> // should be ok
};

const decorator2 = function <T extends { x: number }>(Component: React.StatelessComponent<T>): React.StatelessComponent<T> {
    return (props) => <Component {...props} x={2} ></Component>  // Should be ok, x is known
};

const decorator4 = function <T extends { x: number }>(Component: React.StatelessComponent<T>): React.StatelessComponent<T> {
    return (props) => <Component {...props} y={"blah"} ></Component>  // Should be an error, unknown y
};

Metadata

Metadata

Assignees

No one assigned

    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