Skip to content

zodSchema's returned Schema DocType is in zod form #3

@hollandjake

Description

@hollandjake

Expected Behaviour

When using the zodSchema function, it should generate a zod agnostic mongoose schema.

Current Behaviour

When using the zodSchema function, it generates a mongoose Schema of which its raw type is still the zod schema types.

Context

mongoose/src/index.ts

Lines 50 to 55 in 506bc0e

export function zodSchema<T extends ZodRawShape>(
schema: ZodObject<T>,
): Schema<T> {
const definition = parseObject(schema);
return new Schema<T>(definition);
}

Possible Solution

export function zodSchema<T extends AnyZodObject>(
  schema: T
): Schema<z.infer<T>> {
  const definition = parseObject(schema);
  return new Schema(definition);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions