You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That way we could get a proper type inference when creating new documents. An example:
interfaceIDog{breed: string;name: string;age: number;}typeIDogDocument=IDog&Types.Document;constDogSchema=newSchema<IDogDocument>({breed: {type: String},name: {type: String},age: {type: Number}})constDog=mongoose.model<IDogDocument,Model<IDogDocument>>('dog',DogSchema)constrex=newDog({// type inference here })// or alternatively constrex=newDog<IDog>({// type inference here})
The text was updated successfully, but these errors were encountered:
I'd say this is by design. Mongoose does allow you to pass in arbitrary data into the Model constructor.
Would the new Dog<IDog>({ ... }) syntax work for your case?
vkarpov15
added
discussion
If you have any thoughts or comments on this issue, please share them!
and removed
new feature
This change adds new functionality, like a new method or class
labels
Apr 12, 2021
Would it be possible to change
doc
type to a generic type Z, whereT = Z & Document
?mongoose/index.d.ts
Line 604 in 9e98cd8
That way we could get a proper type inference when creating new documents. An example:
The text was updated successfully, but these errors were encountered: