Closed
Description
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.