Note: I am a beginner in JavaScript
I am currently working on synchronizing an object with a Pinia store and a Python REST API. My goal is to define a type just once without having to duplicate it in the store.
export const useTicketStore = defineStore('ticket', {
state: () => ({
id: null,
status: "",
subject: "",
email: "",
department: null,
ticketType: nulll,
}),
actions: {
save() {
const action = this.id ? axios.patch : axios.post
const url = this.id ? `/api/tickets/${this.id}` : "/api/tickets"
action(url, this).then((response) => {
this.$patch(response.data)
})
}
}
})
Consistency is key throughout my application:
interface Ticket {
id: number | null,
status: string,
subject: string,
email: string,
department: number | null,
ticketType: number | null,
}
My ideal scenario would be something like this
export const useTicketStore = defineStore('ticket', {
state: () => ({
...Ticket
}),
actions: {
...
})
However, attempting to implement the above code snippet leads to a peculiar error:
Uncaught SyntaxError: The requested module '/src/types/ticket.ts' does not provide an export named 'Ticket'