Search code examples
node.jstypescriptmongoosemongoose-schema

Node mongoose typescript how to type { type: ObjectId, ref: 'User' }


I'm use mongoose with typescript following this https://medium.com/@agentwhs/complete-guide-for-typescript-for-mongoose-for-node-js-8cc0a7e470c1

I don't know how to type

following: [{ type: ObjectId, ref: 'User' }],

Can you give me a hint, please?


Solution

  • So basically, what you define in mongoose schema only for mongoose to understand and type script doesn't care about it. If you populate following when retrieve record your interface will be following: User[], if not it will be an array of string string[]