-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
JSX expression type inferencing. #6208
Comments
+1, would also be very useful for usage without React. |
This is a common misunderstanding of how React works.
If you have code like this: class MyElement {
constructor() {
console.log('ctor invoked');
}
render() {
return <div>Hello world</div>;
}
}
console.log('Creating an element');
let x = <MyElement />;
console.log('Rendering it');
ReactDOM.render(x, document.getElementById('target')); You'll see that the output is: Creating an element
Rendering it
ctor invoked Note that the class is not instantiated at the point where we wrote |
I think you are misunderstanding, I am implementing |
It's very confusing to call your library React as well 😄 One of our decision points when implementing JSX support was what non-React consumers of JSX were doing. We can't support every possible library (for example, we don't know how they determine what the set of valid attributes are), so we chose to implement a conservative set that didn't have to provide per-object data. This was also an issue for allowing React itself because things like If your library (or one with identical behavior) becomes popular and has well-defined semantics, we can look into how to support it more fully. |
You are right, it is confusing to have to define I guess what I really want is But before doing that, I would like to know if it is even possible to infer a JSX expression type from the |
TypeScript doesn't look at It's certainly possible to support this pattern (can I call it "XAML-like" ?). I'd like to understand more what its rules are and what other libraries are doing this. Function call resolution might be the right pattern, or maybe something else, depending on exactly how it works. |
I am working on a jsx library for using CustomElements, and I would like to be able to use the element instance type directly from a JSX expression. Reading through #3203 it seems that
JSX.Element
is the final return type of all JSX expressions.Could the JSX expression type not be inferred by evaluating the return type of
React.createElement
? i.e. run the type-inferencing as if the code has been de-sugared.Consider:
Notice the inconsistency of the type inferencing between JSX and it's de-sugared equivalent.
The text was updated successfully, but these errors were encountered: