Skip to content

Typescript incorrectly emits metadata type 'Object' instead of 'String' for string literal types #10809

@JohnWeisz

Description

@JohnWeisz

TypeScript Version: 2.0.2.0 beta

Code

function PropDeco(target: Object, propKey: string | symbol) { }

class Foo {
    @PropDeco
    public foo: "foo" | "bar";
}
--experimentalDecorators  --emitDecoratorMetadata

Expected behavior:

Since the runtime type of Foo.foo is String, I believe the compiler should emit the following metadata definition:

__metadata('design:type', String)

Full code:

function PropDeco(target, propKey) { }
var Foo = (function () {
    function Foo() {
    }
    __decorate([
        PropDeco, 
        __metadata('design:type', String)
    ], Foo.prototype, "foo", void 0);
    return Foo;
}());

Actual behavior:

However, instead of String, the compiler emits Object as the detected type of Foo.foo:

__metadata('design:type', Object)

Full code:

function PropDeco(target, propKey) { }
var Foo = (function () {
    function Foo() {
    }
    __decorate([
        PropDeco, 
        __metadata('design:type', Object)
    ], Foo.prototype, "foo", void 0);
    return Foo;
}());

I believe this is incorrect.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions