Skip to content

Incorrect metadata emitted for property decorators when the property type is inferred (e.g. from an assignment), but not explicitly defined. #13174

@JohnWeisz

Description

@JohnWeisz

TypeScript Version: 2.1.4

Code

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

class Foo {
    @PropDeco
    public foo = "bar";
}

Expected behavior:

Since the runtime type (constructor reference) of Foo.foo is supposed to be String, the compiler should emit String as the type of Foo.foo, as it does when the property has an explicitly defined type (i.e. foo: string = "bar"):

__metadata("design:type", String)

Actual behavior:

The compiler emits Object as the type of Foo.foo, which I believe is incorrect:

__metadata("design:type", Object)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions