Description
Problem
Currently meta-programming with TypeScript is not ideal. There are a lot of features which support meta-programming but there is a lot of room for getting better.
This feature request targets code generation based on rules/declarations and meta information.
I've written pretend and realized that its not syntactically good to use decorators (as meta-information) to drive code generation.
But it could be quite intuitive for developers to do so.
The current limitations are the following:
- Interfaces could not be target for decorators
- Classes (which could be decorated) must have methods with body, but the body is not necessary since it is generated and only target for the meta-data
- Empty method bodies with return types are considered failure for linters and the tsc
- Even if interfaces could be decorated, they are not part of the emitted code (which is okay)
Solution / Idea
Allow for decorating interfaces.
Probably not only interfaces but a syntactic extension (e.g. #decorator()
) to annotate other code as well (e.g. class properties, functions, variables, ...)
These decorators could then be used as hooks into the tsc code emitter and drive code generation.
With this feature meta-programming would get a lot gain, since valid typescript code could be annotated and valid js-code could be emitted. E.g. Interfaces could generate classes.
Something like active annotations like in xtend would be a good start.
If this idea would be considered acceptable I would be glad to contribute more examples and better explanations.