I am trying to export a function in ECMAScript 6 so I can import it and use it in other files to have DRY code.
However, I receive the following error:
You can only use decorators on an export when exporting a class (16:0) while parsing file:
@idempotent
export function totalItems() {
this.cart.items.forEach((dish) => total += item.qty);
return total;
}
How can I fix this problem?
What you're trying to do is not supported. The decorator proposal (which is not yet standardized) only includes @decorators for classes definitions and their methods, not for function definitions.
You may want to create a function decorator/wrapper function to be used like this instead:
export const totalItems = idempotent(function() {
let total;
this.cart.items.forEach((dish) => total += item.qty);
return total;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With