git-zodyac / mongoose

Converts your Zod schemas into fully-functional Mongoose schemas
https://www.npmjs.com/package/@zodyac/zod-mongoose
31 stars 5 forks source link

zodSchemaRaw return type #22

Open leosilberg opened 1 week ago

leosilberg commented 1 week ago
export const UserSchema = z.object({
  email: z.string().unique(),
  password: z.string(),
  firstName: z.string(),
  lastName: z.string(),
});

const schema = zodSchemaRaw(UserSchema);
const userSchema = new Schema(schema, {
  toJSON: { virtuals: false, getters: true },
});

userSchema.pre("save", async function (next) {
  if (!this.isModified("password")) return next();
  const salt = await bcrypt.genSalt(10);
  this.password = await bcrypt.hash(this.password, salt); //Argument of type '_Field<ZodString> | _Schema<ZodString>' is not assignable to parameter of type 'string | Buffer'.
 // Type '_Field<ZodString>' is not assignable to type 'string | Buffer'
});

It may be related to the same return types as in #3 but for zodSchemaRaw

leosilberg commented 1 week ago

Also following the docs I'm getting a type error

schema.email.index = true; //Property 'index' does not exist on type '_Field<ZodString> | _Schema<ZodString>'. Property 'index' does not exist on type '_Field<ZodString>