pick types from class by specific decorator #48413
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
trusktr commentedMar 25, 2022
•
edited
I am aware that decorators can not currently modify the type of a class and this is not a feature request for that.
Suggestion
typescript pick properties by decorator
My suggestion meets these guidelines:
This is a feature request to be able to pick properties from a class type based on a particular decorator or set of decorators.
This would probably have to be a type with an intrinsic implementation.
The ability to do something this:
Makes it easier to do things, for example pick properties that represent attributes for use in JSX.
Here's an example of a Custom Element for use in some hypothetical JSX framework, and we want only certain properties to be available via JSX:
Without such a tool, we must resort to more repetitive code, with the opportunity for human error. In the following snippet, the user has to remember to keep the list of strings up to date with the decorator properties; which leads to more work, and easy to get it wrong:
Note that if the class has 20 properties decorated with
@prop, they have to make sure they list the same 20 properties in the string list. They could accidentally also include the wrong properties, like so:The text was updated successfully, but these errors were encountered: