Allow JSX element tags to be symbols #38367
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
Search Terms
es6 symbols JSX createElement element tag type intrinsic host
Suggestion
Allow JSX element tags to be ES6 symbols instead of just strings, functions or classes.
Use Cases
JSX-based libraries like React have adopted the convention of using special upper-cased symbols as the tag of the JSX expression (
<Fragment />
,<Suspense />
) as a way to provide intrinsic elements which aren’t callable and whose behavior are defined by the library rather than the tag.Currently, TypeScript only allows JSX tags to be strings, functions or classes as defined by the JSX interface, and will throw errors like the following if Symbols are used:
Libraries are therefore forced to lie about the actual typings of Symbol tags as something other than a
unique symbol
. For instance, React defines Symbol tags asExoticComponent
and pretends that the symbols are callable (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L358-L364). The framework I work on (Crank.js) just defines symbols meant to be used as tags asany
but this then has further repercussions when I attempt to, for instance, use these symbol types in interfaces.Symbols are useful because they:
IntrinsicElements
interfaces to be strongly typed.Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: