Support non-constructor JSX factory functions #37733
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
TypeScript Version: 3.3.3 to 3.8.3
Search Terms:
jsx factory function constructor component ElementClass
Expected behavior:
I'm trying to pass a factory function instead of a class component as a JSX element constructor function. It should be possible according to the Handbook, as described here. See the example under the
Type checking -> class component
section (I can't deep-link with hash/anchor because the server isn't properly configured :( ). I should get no errors with the code provided below.Actual behavior:
I get the following error:
From what I can tell, this used to work, but the behavior broke somewhere between v3.1.6 and v3.3.3 (as tried in the Playground). I'm guessing there was some change that altered detection between React function components and class components and that change introduced this bug. I'm not even sure if React runtime even allows factory functions, but my use case is a custom library and I'm not using React at all. This error is the same regardless of using React or not.
Also, with the exact example from the Handbook, because the JSX.Element is not specified explicitly, there is no error, even when there should be one. See Playground Link for Handbook example
Related Issues:
#5740
#5478
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: