Add options to a Vuex plugin using TypeScript

Share this video with your friends

Send Tweet

In some cases we may want to pass some options to a Vuex plugin, in order to make it more customizable. This lessons shows how can you make a Vuex plugin accept a persist parameter in order to save the state to the localStorage in TypeScript

Paul
Paul
~ 7 years ago

Hi there, when implementing a plugin that utilises a higher order function. I am unable to compile the project, due to a Typescript error:

Types of property 'plugins' are incompatible. Type 'void[]' is not assignable to type 'Plugin<RootState>[] | undefined'.

Any advice would be great on how to resolve this.

Paul
Paul
~ 7 years ago

Solved the issue. So it turns out that when using arrow functions. The return is only implicit if instead of a code block after => you put an expression.