ts-mongoose
ts-mongoose copied to clipboard
ExtractProps doesn't cast the _id type defined in the schema
Hi,
I am changing the type of the _id in the schema to String, eg:
import { createSchema, Type, ExtractProps } from 'ts-mongoose';
const UserSchema = createSchema({
_id: Type.string(),
});
export type User = ExtractProps<typeof UserSchema>;
const user = { _id: 'aa' } as User;
So it seems the ExtractProps is not casting the _id to string, therefore User._id type is been defined as ObjectId instead of string
@zfattuhi-sonalake Have you tried using { _id : false }
option? Like following:
import { createSchema, Type, ExtractProps } from 'ts-mongoose';
const UserSchema = createSchema({
_id: Type.string(),
},
{ _id: false });
export type User = ExtractProps<typeof UserSchema>;
const user = { _id: 'aa' } as User;