Skip to content
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

emitDecoratorMetadata does not preserve array types on fields #12463

Closed
arciisine opened this issue Nov 23, 2016 · 3 comments
Closed

emitDecoratorMetadata does not preserve array types on fields #12463

arciisine opened this issue Nov 23, 2016 · 3 comments
Labels

Comments

@arciisine
Copy link

@arciisine arciisine commented Nov 23, 2016

TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
All Typescript Versions

Code

class Post {
     tags: string[];
}

Expected behavior:
There should be metadata added to indicate the type of array.

class Post {
   constructor() {}
}
__decorate([
    __metadata('design:type', [String])
], Post.prototype, "tags", void 0);

Actual behavior:

class Post {
   constructor() {}
}
__decorate([
    __metadata('design:type', Array)
], Post.prototype, "tags", void 0);

If you look at how rest parameters are handled, there is precedent for preserving array type:

Given:

class Post {
     tags: string[];
     constructor(...tags:string[]) {}
}

The output is:

class Post {
   constructor() {}
}
__decorate([
    __metadata('design:type', Array)
], Post.prototype, "tags", void 0);
Post = __decorate([    
    __metadata('design:paramtypes', [String])
], Post);
@arciisine

This comment has been minimized.

Copy link
Author

@arciisine arciisine commented Dec 6, 2016

@rbuckton It looks like you have done a great deal of the work on the file (src/compiler/transformers/ts.ts). Do you know if PRs would be accepted for this change, or if this change is even acceptable?

@arciisine

This comment has been minimized.

Copy link
Author

@arciisine arciisine commented Dec 19, 2016

So after thinking about this for a bit, I realized that the param types is actually reducing string[] to String to handle the variadic arguments. Would it be possible to treat the array as a generic class? Array<string>, and perhaps store all generic types in the metadata?

@DanielRosenwasser

This comment has been minimized.

Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Dec 20, 2016

Closing as a duplicate of #3015.

@mhegazy mhegazy closed this Dec 21, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.