Type Alias InferObjectSchema<S>

InferObjectSchema: {
    [K in keyof S as S[K]["nullable"] extends true ? never : K]: InferFieldDef<
        S[K],
    >
} & {
    [K in keyof S as S[K]["nullable"] extends true ? K : never]?:
        | InferFieldDef<S[K]>
        | null
}

Infers the TypeScript type from an ObjectSchema definition.

  • Primitive fields map to their TS equivalents via PrimitiveTypeMap
  • Enum fields become a union of their values (values[number])
  • Nested object fields recurse through InferObjectSchema
  • Array fields become T[] where T is inferred from items
  • Fields with nullable: true become optional and accept null (T | null | undefined)

Type Parameters

const schema = {
name: { type: "string" },
age: { type: "number", nullable: true },
status: { type: "enum", values: ["active", "inactive"] },
tags: { type: "array", items: { type: "string" } },
geo: { type: "object", fields: { lat: { type: "number" }, lng: { type: "number" } } }
} as const satisfies ObjectSchema;

type MyType = InferObjectSchema<typeof schema>;
// {
// name: string;
// status: "active" | "inactive";
// tags: string[];
// geo: { lat: number; lng: number };
// age?: number | null;
// }