Open
Description
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;
}