Inferring JSX expression types from the respective JSX function instead of the JSX namespace #3393
Romich123
started this conversation in
Design Discussion
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
All JSX options except
react-nativeandpreserveconvert JSX expressions to function calls, so why not treat them as function calls?The problem
Current JSX requires you to declare a global namespace, which feels outdated. Also, it doesn't support conditional return types.
For example:
And this behaviour couldn't be changed with the current TS implementation. However, if it was inferred from JSX arguments, just like:
It could be done very easily with a function like this:
Other reasons
JSX is not only used for browser apps. It can also be used for 3D scene compositions and TUI applications, in both of which elements are usually more complex than in the browser, sometimes requiring a certain type of children.
Transition
I don't think many libraries would work with that right now, so it could be done with some option like this:
{ "compilerOptions": { ... "jsxUseFunctionType": true ... } }Most JSX is used after creating a project with a CLI, so every framework/library could set the flag as needed for comfortable use.
Beta Was this translation helpful? Give feedback.
All reactions