-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
Maybe I'm doing something wrong here but I'm trying to store a callback function in a metadata library but getting pretty nasty type errors. The error happens when the argument to my callback contains a ZodType.
Here's a minimal example:
import z, { ZodType } from "zod";
type Context = {
schema: ZodType;
};
type MetadataObject = {
a: string;
b: "a" | "b";
};
export const registry = z.registry<
MetadataObject | ((_validationContext: Context) => MetadataObject)
>();
function _text({ context, schema }: { context: Context; schema: ZodType }) {
const found = registry.get(schema);
const _metadata =
found && typeof found === "function"
? found(context) // <- Error
: found
? found
: undefined;
}Either it's something in my setup or drizzle has a problem resolving schema-based arguments to the correct type.
The type error:
Argument of type 'Context' is not assignable to parameter of type '{ schema: { def: { type: "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "optional" | "nonoptional" | "nullable" | "default" | "prefault" | ... 26 more ... | "custom"; error?: ((issue: never) => string | ... 2 more ... | undefined) | undefined; checks?: { ...; }[] | unde...'.
The types of 'schema.def.checks' are incompatible between these types.
Type '$ZodCheck<never>[] | undefined' is not assignable to type '{ _zod: { def: { check: string; error?: ((issue: never) => string | { message: string; } | null | undefined) | undefined; abort?: boolean | undefined; when?: ((payload: { value: unknown; issues: ({ [x: string]: unknown; ... 6 more ...; readonly continue?: boolean | undefined; } | ... 9 more ... | { ...; })[]; aborte...'.
Tested in zod 4.1.12
Metadata
Metadata
Assignees
Labels
No labels