Skip to content
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

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

Closed
JohnWeisz opened this issue Sep 9, 2016 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@JohnWeisz
Copy link

JohnWeisz commented Sep 9, 2016

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.

@mhegazy
Copy link
Contributor

mhegazy commented Sep 9, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants