question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: JSX.ElementType

See original GitHub issue

Hello, 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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:15 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
antanas-arvaseviciuscommented, Oct 5, 2017

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.

2reactions
ceymardcommented, May 12, 2017

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 a HTMLDivElement or an HTMLInputElement instead of just a plain Node 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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - JSX - TypeScript
JSX is an embeddable XML-like syntax. It is meant to be transformed into valid JavaScript, though the semantics of that transformation are ...
Read more >
Type checking JSX: A can of props - INNOQ
In this post, I'd like to describe how JSX type checking in TypeScript actually works and the problems you're going to encounter when ......
Read more >
Error: Element type is invalid: expected a string or a class ...
I receive the following error and stack after I upgraded to the latest version of React Native: Error: Element type is invalid: expected...
Read more >
'errormessage' cannot be used as a jsx component. - You.com
Its element type 'ReactElement<any, any> | Component<ErrorMessageProps, any, ... This doc outlines a few proposals for how React could be updated to make ......
Read more >
дэн on Twitter: "I drop the dependency on JSX every single ...
I wonder if there would be a way to implement proposals in an inherently reversible codemod format. So you get the reverse for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found