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

Created on 9 Sep 2016  ·  1Comment  ·  Source: microsoft/TypeScript

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.

Bug Fixed

Most helpful comment

We should do this for all literal types, including boolean, enum, number, and string.

>All comments

We should do this for all literal types, including boolean, enum, number, and string.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bgrieder picture bgrieder  ·  3Comments

dlaberge picture dlaberge  ·  3Comments

Antony-Jones picture Antony-Jones  ·  3Comments

wmaurer picture wmaurer  ·  3Comments

weswigham picture weswigham  ·  3Comments