import { _GettersTree, defineStore } from 'pinia';
interface Todo {
todo: string;
}
interface State {
count: number;
todos: Todo[];
}
interface Actions {
addTodo: (todo: Todo) => void;
increment: () => void;
resetState: () => void;
}
interface Getters extends _GettersTree<State> {
getCount: () => number;
getTodos: () => Todo[];
}
export const useMyStore = defineStore<string, State, Getters, Actions>({
id: 'todo',
state: () => ({
count: 0,
todos: [],
}),
getters: {
getCount() {
return this.count;
},
getTodos() {
return this.todos;
},
},
actions: {
increment() {
this.count++;
},
addTodo(todo) {
this.todos.push(todo);
},
resetState() {
this.count = 0;
this.todos = [];
},
},
});
![Cover image for How to add typescript types to a pinia options store 🍍](https://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F12nt9zevxlr8s46x59il.jpg)
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)