-
-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: compatibility with zod or similar #253
Comments
You could use https://github.com/StefanTerdell/zod-to-json-schema for this. |
Apparently it not works correctly, see this case: //Original Schema
type StoreOptions = {
darkMode: boolean
frameStyle: "windows" | "macos"
frameTheme: "light" | "dark" | "auto"
}
export const optionsSchema: ElectronStore.Schema<StoreOptions> = {
darkMode: {
type: "boolean",
default: true
},
frameStyle: {
type: "string",
enum: ["windows", "macos"],
default: "windows"
},
frameTheme: {
type: "string",
enum: ["light", "dark", "auto"],
default: "auto"
}
} It Works Correctly, now see it: // Conversion to zod schema
const zodOptionsSchema = z.object({
darkMode: z.boolean().default(true),
frameStyle: z.enum(["windows", "macos"]).default("windows"),
frameTheme: z.enum(["light", "dark", "auto"]).default("auto")
})
export const optionsSchema = zodToJsonSchema(zodOptionsSchema) It's a correct conversion right? But it causes some type errors like "The types are incompatible" Apparently |
Does it work if you define your optionsSchema like this? // Conversion to zod schema
const zodOptionsSchema = z.object({
darkMode: z.boolean().default(true),
frameStyle: z.enum(["windows", "macos"]).default("windows"),
frameTheme: z.enum(["light", "dark", "auto"]).default("auto")
})
type Options = z.infer<typeof zodOptionsSchema>
export const optionsSchema: ElectronStore.Schema<Options> = zodToJsonSchema(zodOptionsSchema) |
I get this error:
On this line: export const optionsSchema: ElectronStore.Schema<Options> = zodToJsonSchema(zodOptionsSchema) |
Did anyone find a good solution for it? |
I made a package called zod-electron-store, you can find on npm. |
Hello, I recently discovered zod lib and used it in some projects. It's very easy create validation schemas and, in my opinion, more human friendly to use.
I've migrating some sistems for typescript and reciving a lot of errors related of schemas, it would be interesting if you could add some kind of compatibility with zod or similar more or less like this:
The text was updated successfully, but these errors were encountered: