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
Type instantiation is excessively deep and possibly infinite.ts(2589) #12277
Comments
Original Issue in typegoose (because author does not seem to have linked it): typegoose/typegoose#752 this issue seems to be about |
i have locally tried the issue, and could reproduce it in typegoose and plain mongoose // NodeJS: 18.7.0
// MongoDB: 5.0 (Docker)
// Typescript 4.7.4
import * as mongoose from 'mongoose'; // mongoose@6.5.2
type DocumentType<T> = mongoose.Document<any, any, T> & T;
interface BaseModelClassDoc {
firstname: string;
}
const baseModelClassSchema = new mongoose.Schema({
firstname: String,
});
const BaseModel = mongoose.model<mongoose.Model<DocumentType<BaseModelClassDoc>>>('test', baseModelClassSchema);
(async () => {
await mongoose.connect(`mongodb://localhost:27017/`, {
dbName: 'verifyMASTER',
});
await BaseModel.bulkWrite([
{
updateOne: {
update: {
firstname: 'test', // Type instantiation is excessively deep and possibly infinite.ts(2589)
},
filter: {
firstname: 'asdsd',
},
},
},
]);
await mongoose.disconnect();
})(); Reproduction Repository / branch: https://github.com/typegoose/typegoose-testing/tree/verify752 |
This issue does not happen on 6.5.1 |
@IslandRhythms @hasezoey I seem to have the same problem with mongoose=6.5.3, typescript=4.8.2 and typegoose=9.11.2 |
@AbdelrahmanHafez tagging you as well as i missed that you're a collaborator |
@IslandRhythms why was the "has repro script" label removed when it stated mongoose version 6.5.2? i have also tested now 6.5.3 and can reproduce the error (with the same code), i have also tried typescript 4.8.2 (both changes can be found in the linked repository+branch) |
@hasezoey we use the |
thats what i assumed
isnt that the purpose of having |
|
|
thanks for the explanation @IslandRhythms, it seems we had a different understanding of the label meanings, thanks for clarifying (personally in my projects i have |
Still an issue with Typescript=4.8.3, which seemed to have fixes for type narrowing.. |
@SK-FComputer with what mongoose version were you testing? |
With 6.6.0 and 6.5.5 if i remember correctly |
If it helps, here's a minimal repro in the Typescript playground. No way to pin the versions there that I can see but presumably it's using the latest version of each package. I'm also seeing in my actual work with import { AnyBulkWriteOperation, ObjectId } from 'mongodb';
import { Document } from 'mongoose';
const update : AnyBulkWriteOperation<Document> =
{
updateOne: {
filter: { _id: new ObjectId() },
update: {
$set: {
"abc": "def"
}
}
}
}; |
Based off of @hasezoey 's script here: #12277 (comment) I'd advise either using Mongoose's automatic type inference: const BaseModel = mongoose.model<typeof baseModelClassSchema>('test', baseModelClassSchema); or calling const BaseModel = mongoose.model<BaseModelClassDoc>('test', baseModelClassSchema); rather than trying to manually create a hydrated document type and passing it to |
…ing bulkWrite() with type that extends from document Fix #12277
fix(types): avoid "excessively deep" type instantiation error when using bulkWrite() with type that extends from document
Prerequisites
Mongoose version
6.5.2
Node.js version
14.18.3
MongoDB version
4.4
Operating system
No response
Operating system version (i.e. 20.04, 11.3, 10)
No response
Issue
when use bulkwrite show ts error can help for solved this error
this my model:
sample code:
in this block show error:
and show this error:
The text was updated successfully, but these errors were encountered: