ts-mongoose icon indicating copy to clipboard operation
ts-mongoose copied to clipboard

ExtractProps doesn't cast the _id type defined in the schema

Open zfattuhi-sonalake opened this issue 4 years ago • 1 comments

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 avatar Dec 30 '19 11:12 zfattuhi-sonalake

@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;

lchimaru avatar Feb 20 '20 19:02 lchimaru