-
with current generation of ts-friendly libs there is usually a way to infer type definitions from the lib data structures for example with zod we can do something like this export const categorySchema = z.object({
id: z.number(),
name: z.string().min(1),
color: z.string(),
});
export type CategoryModel = z.infer<typeof categorySchema>; with drizzle orm we can do something like this export const users = sqliteTable("users", {
id: text().primaryKey(),
createdAt: text(),
updatedAt: text().notNull(),
});
export type User = typeof users.$inferSelect; is there a way to do the same with zustand? meaning instead of defining state interface and using it as a generic for |
Beta Was this translation helpful? Give feedback.
Answered by
dai-shi
Jan 1, 2025
Replies: 1 comment 3 replies
-
There would be several ways, but I'd do this: const useMyStore = create(combine({
count: 0,
}, (set) => ({
inc: (by = 1) => set((state) => ({ count: state.count + by }));
}));
type MyState = ReturnType<(typeof useMyStore)['getState']>; |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
vorant94
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There would be several ways, but I'd do this: