Skip to content

emitDecoratorMetadata does not preserve array types on fields #12463

Closed
@arciisine

Description

@arciisine

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions