Proposal: JSX.ElementType
See original GitHub issueHello,
There are many GUI frameworks (ExtJs, SmartClient, OpenUI5) which do not works in React way and they could be easily be integrated with JSX/TSX if their JSX expressions would return correct “element type” e.g.
const listGrid = <ListGrid/> ; // should be type of ListGrid or isc.IListgrid, not JSX.Element
My proposal would be to add new special type into global JSX
namespace - ElementTypeProperty
.
JSX.ElementTypeProperty
Given an element instance type, we need to produce a type that will be return type of that JSX element. We call this the element type.
The interface JSX.ElementTypeProperty defines this process. It may have 0 properties, in which case element instance type will be element type. Or 1 property, in which case the element type will be the type of that property type of element instance type.
Note: Intrinsic lookup is not affected by ElementTypeProperty.
Related: https://github.com/Microsoft/TypeScript/issues/13746
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:15 (3 by maintainers)
Top GitHub Comments
Hi, looks like this feature is still not on your (public) roadmap list, is there are any technical issues to implement it? (“JSX element type resolver to be similar to resolving the return type of a function.”) If it’s technically doable then I can try to contribute and implement it, just some guidelines on how to approach it would be nice to have.
I have a use case for a library I’m writing where I’m basically using tsx to generate DOM nodes directly (with extra sauce on top).
I would like a lot to be able to specify that
<div/>
returns aHTMLDivElement
or anHTMLInputElement
instead of just a plainNode
as I am doing right now with some ugly casts.Couldn’t the whole tsx transform simply apply the function call and type check it ? My guess is that it would also solve the whole generics issue since the type inferer works well with them – directly calling the factory function without using tsx generally works fine…