For JSX Class Components, allow attributes based on the type of the class constructor #47905
Open
5 tasks done
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
Suggestion
Currently, only the first argument of the constructor of a Class Component can be used as attributes in JSX. This is not in accordance with the JSX spec: In pure JavaScript, there is no problem at all defining a JSX pragma that uses JSX attributes as the third argument to construct the class.
🔍 Search Terms
JSX, React, CDK, class, constructor
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
A generic way to introduce this would be e. g.
📃 Motivating Example
It is now possible to define JSX Class Components that take their attributes from any part of the constructor function with help of
ElementAttributesFromConstructor
. Previously, it was only possible to use the first argument to the constructor.This is helpful when adding JSX to existing structures. One example is the AWS CDK which uses Constructs in the following form:
When setting
ElementAttributesFromConstructor
like thisTypeScript will support you when using classes in JSX:
💻 Use Cases
Currently, JSX is still mostly used for React and very similar libraries (e. g. Preact, Vue). But there are already other use cases for JSX (e. g. https://github.com/developit/jsxobj, https://github.com/dbartholomae/jsx-readme).
One ongoing discussion is about configuring AWS CDK via JSX, which is limited by this: AWS CDK uses the third constructor parameter for properties, and while this works in JavaScript, the TypeScript types do not allow for it.
The text was updated successfully, but these errors were encountered: