Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Samples code in "Metadata" section of "Decorators" page is wrong #1302

@JeffreyZhao

Description

@JeffreyZhao

Currently (with comments added to explain the issue):

function validate<T>(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor<T>) {
    let set = descriptor.set;
    descriptor.set = function (value: T) {
        let type = Reflect.getMetadata("design:type", target, propertyKey); // "target" should be "this"
        if (!(value instanceof type)) {
            throw new TypeError("Invalid type.");
        }
        set.call(target, value); // "target" should be "this"
    }
}

We should use this instead of target in those two lines with comments. I will make a PR for it later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions