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.
We should do this for all literal types, including boolean, enum, number, and string.
Most helpful comment
We should do this for all literal types, including boolean, enum, number, and string.