-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DecoratorsOf<TClass, TFieldName> - Expose decorators to the type system #58836
Comments
As you noted, decorators donβt affect the type of a class at all, so how would this even work? The information just isnβt there. Decorators modifying types is, AFAICT, a prerequisite for this feature. Also:
It is. |
Good point, I should clarify. This feature requires decorators to be exposed to the typing system (which is why this is a feature request to TypeScript, instead of just some library), but it does not require the decorators API to allow an end-user to modify the typing system in some way. The latter is what I referred to by:
I suppose it could have a different format to make it look more like a language feature than a type (e.g. i.e. The purpose of the type isn't utility but basic functionality. |
Looks similar to or duplicate of #48413 |
Yup! Very similar. Only a couple of minor differences:
I should also mention #4881 which I think is the equivalent of:
|
This doesn't seem to generalize very well. Decorators can have arguments and those arguments will absolutely be needed to make the kinds of decisions being discussed here. #4881 or its alternatives seem like the scalable approach. |
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
decorators, decorated, tc39
β Viability Checklist
β Suggestion
Implement a new generic type that exposes the existence of decorators to the type system:
The type would return a union of the types of all decorators applied to the field/class/etc... which allows deriving new types based on the presence or absence of decorators.
Note: This proposal becomes unnecessary if decorators gain the ability to modify the type of the fields/classes/etc... that they decorate.
π Motivating Example
You can see a full example in the TypeScript Playground.
As a brief inline example, consider an application with networking capabilities on its data structures. It uses decorators to annotate which fields are networked (and provide the networking implementation for them).
A client that only has remote access to some data structures would only be able to access these remote fields, and not any local ones, but there is currently no way to generate this TypeScript type.
π» Use Cases
The text was updated successfully, but these errors were encountered: