Skip to content

Pass third argument in createDecorator without modification #265

Open
@downace

Description

@downace

Example: I want to write Static decorator which can be used to add non-reactive instance properties with initial value. Something like this:

const Static = () => {
    return createDecorator((opts, key, descriptor) => {
        descriptor.enumerable = false;
        const initialValue = typeof descriptor.initializer === 'function'
            ? descriptor.initializer()
            : undefined;
        const beforeCreate = function() {
            this[key] = initialValue;
        };
        (opts.mixins || (opts.mixins = [])).push({ beforeCreate });
    });
};

But descriptor is undefined because of these lines in createDecorator:

if (typeof index !== 'number') {
    index = undefined;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions