-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Domain: DecoratorsThe issue relates to the decorator syntaxThe issue relates to the decorator syntaxNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TSC 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
abierbaum, alex-kinokon, inad9300, httpdigest, IonelLupu and 48 morecsbenjamin, alvaroloes, NSExceptional, l00k, psteinroe and 5 more
Metadata
Metadata
Assignees
Labels
Domain: DecoratorsThe issue relates to the decorator syntaxThe issue relates to the decorator syntaxNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript