Open jrmyio opened 6 years ago
No, it's not working with getters since decorator method in source code doesn't check if you're applying decorator on regular method or getter:
function decorator(fn) {
return opt => (
typeof opt==='function' ? fn(opt) : (target, key, desc) => {
desc.value = fn(desc.value, opt, target, key, desc);
}
);
}
This would work with getters:
function decorator(fn) {
return opt => (
typeof opt==='function' ? fn(opt) : (target, key, desc) => {
if (desc.value) desc.value = fn(desc.value, opt, target, key, desc);
if (desc.get) desc.get = fn(desc.get, opt, target, key, desc);
}
);
}
PR welcome!
(tested in Typescript)
Throws an error:
Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
For reference: https://github.com/darrylhodgins/typescript-memoize does work.