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

weswigham picture weswigham  路  3Comments

wmaurer picture wmaurer  路  3Comments

jbondc picture jbondc  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

seanzer picture seanzer  路  3Comments