Skip to content

emitDecoratorMetadata does not preserve array types on fields #12463

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

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
Duplicate An existing issue was already created

Comments

@arciisine
Copy link

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
Copy link
Author

@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
Copy link
Author

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
Copy link
Member

Closing as a duplicate of #3015.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Dec 20, 2016
@mhegazy mhegazy closed this as completed 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.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants