You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I found something. When merging two schema of objects with a different policy for unknown keys (one "strict" and the other "strip"), the inferred type of the resulting schema is inconsistent with the runtime behavior.
// This one is "strict"
const schemaA = z
.object({
a: z.string(),
})
.strict()
// This one is "strip"
const schemaB = z
.object({
b: z.string(),
})
// Merge them
// According to the docs, the policy from B overrides the one from A, so it should be a "strip"
const mergedSchema = schemaA.merge(schemaB)
// This doesn't throw an error : the schema is indeed "strip'
mergedSchema.parse({
a: 'xxxxx',
b: 'xxxxxx',
other: 'xxxxx',
})
// However the inferred type of the merge schema uses "strict"
// This compiles, it should not
const strictSchema: z.ZodObject<any, 'strict'> = mergedSchema
// This doesn't compile, it should
const stripSchema: z.ZodObject<any, 'strip'> = mergedSchema
The text was updated successfully, but these errors were encountered:
Hi, I found something. When merging two schema of objects with a different policy for unknown keys (one "strict" and the other "strip"), the inferred type of the resulting schema is inconsistent with the runtime behavior.
The text was updated successfully, but these errors were encountered: