Decorator Metdata: expose array element type
See original GitHub issueTSC 175, target ES6, Node 5.6
Sample class with decorated properties:
@sg.DMClass
export class User implements IUser {
@sg.DMProperty
firstName: string;
@sg.DMProperty
lastName: string;
@sg.DMProperty
friends: User[];
}
Property decorator:
export function DMProperty(target: any, key: string) {
var type = Reflect.getMetadata("design:type", target, key);
}
Current behaviour: When the decorator gets called for property “friends”, “type” is “Array” and the captured type (“User”) is lost.
Expected behaviour “type” should contain the captured type (“User”), too
Following very dirty work-around does the job: I modified tsc’s method “emitSerializedTypeNode”:
function emitSerializedTypeNode(node) {
if (node) {
console.log("*** emitSerializedTypeNode: node.kind: ", node.kind);
switch (node.kind) {
...
case 157:
// Begin dirty ---------------------------------------------------------------------------
var _elemType = node.elementType.typeName.text;
write("{name: 'Array<" + _elemType + ">', type:'Array', elemType:'" + _elemType + "'}");
console.log("*** emitSerializedTypeNode: Array, type: ", node.elementType.typeName.text);
// End dirty -----------------------------------------------------------------------------
return;
case 150:
...
Best Mind
Issue Analytics
- State:
- Created 8 years ago
- Reactions:54
- Comments:43 (4 by maintainers)
Top Results From Across the Web
Documentation - Decorators - TypeScript
A Decorator is a special kind of declaration that can be attached to a class ... When getFormat is called, it reads the...
Read more >get List of reflect-metadata decorated fields of class
I composed my own property decorator and it's called Field . How to get list of fields/properties, which are decorated by Field ,...
Read more >@Decorator · ng-metadata
A decorator for adding NgModule metadata to a class. NgModules are how we register our dependencies (such as Component, Directives, Pipes and Providers), ......
Read more >How to preserve Function Metadata while using Decorators?
Copying decorator metadata is an important part of writing decorators. If you forget to use @wraps, you'll find that the decorated function ...
Read more >Types and Fields - TypeGraphQL
It marks the class as the type known from the GraphQL SDL or ... To do this, we use the @Field decorator, which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You may see low reaction numbers for this feature but it is waited by a lot of people. We need to transform JavaScript/Typescript and make it compete with languages like Java.
For example, this feature will allow me to build a very beautiful database ORM just by using class properties and no any workarounds with decorators.
Hi, any news?