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
TypeScript: remove support for document interfaces that extends Document
#11615
Comments
Hi @vkarpov15, Thanks for the notice ! Sometime we need the document version in our applications. // Do this:
interface User {
name: string;
email: string;
// Use `Types.ObjectId` in document interface...
organization: Types.ObjectId;
}
const schema = new Schema<User>({
name: { type: String, required: true },
email: { type: String, required: true },
// And `Schema.Types.ObjectId` in the schema definition.
organization: { type: Schema.Types.ObjectId, ref: 'Organization' }
});
// Document type to match correct type after using findOne() ... (no lean)
type UserDocument = User & Document; I think it wouldn't impact performances but we've had severe performances issues (and sometime still have), so it'd be great to have confirmation. |
@tristanguerin that approach works. We recommend doing What sort of performance issues are you seeing and what version of Mongoose are you using? |
@vkarpov15 Thank you for your answer and your recommendations. |
…ather than separate TVirtuals and TInstanceMethods Re: #11615
…ies to promises in TypeScript Re: #11615
Drop support for document interfaces that `extends Document`
Do you want to request a feature or report a bug?
Neither
What is the current behavior?
We've been recommending people not use
extends Document
for the document interface generic param toSchema
,Model
, etc.See: https://mongoosejs.com/docs/typescript.html#using-extends-document
This makes our TypeScript types considerably more complex, and also adds a non-trivial amount of performance overhead because of all the places where we need to
Omit<>
document keys.If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: