Skip to content

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

Closed
@mattmccutchen

Description

@mattmccutchen

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitter

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions