Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zfattuhi-sonalake opened this issue Dec 30, 2019 · 1 comment
Open

Comments

@zfattuhi-sonalake
Copy link

zfattuhi-sonalake commented Dec 30, 2019

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

@lchimaru
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants