Skip to content

JSX takes apparent type of props for SFCs but not for component classes?? #27385

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

Closed
mattmccutchen opened this issue Sep 27, 2018 · 1 comment · Fixed by #27627
Closed

JSX takes apparent type of props for SFCs but not for component classes?? #27385

mattmccutchen opened this issue Sep 27, 2018 · 1 comment · Fixed by #27627
Assignees
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter

Comments

@mattmccutchen
Copy link
Contributor

mattmccutchen commented Sep 27, 2018

This bug underlies some of the confusion in https://stackoverflow.com/q/52525133 .

TypeScript Version: master (0a97663)

Search Terms: JSX props apparent type parameter constraint SFC stateless function component class

Code

import * as React from "react";

function test<P>() {
    let MySFC = function(props: P) {
        return <>hello</>;
    };
    class MyComponent extends React.Component<P> {
        render() {
            return <>hello</>;
        }
    }
    let x = <MySFC />;  // Actual: compiles OK, unsound
    let y = <MyComponent />;  // Actual: compile error
}

Expected behavior: Consistent behavior for x and y.

Actual behavior: As marked.

Playground Link: N/A, React dependency

Related Issues: Taking the apparent type for SFCs was introduced in #15789. When I revert #15789, I get a few test failures that look like they should be fixable other ways. I might be willing to try my hand at a PR for this bug if you tell me the right approach.

@mattmccutchen
Copy link
Contributor Author

I'm guessing that fixing this will expose a lot of users to #27484, so we should probably address that one first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSX/TSX Relates to the JSX parser and emitter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants