-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
TS2589: Type instantiation is excessively deep and possibly infinite #11787
Comments
import * as mongoose from 'mongoose';
import { UserDocument, UserModel, UserSchema, UserObject} from './src/interfaces/mongoose.gen'
const UserSchema: UserSchema = new mongoose.Schema({
name: String
});
const User = mongoose.model<UserDocument, UserModel>('User', UserSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const entry = await User.create({ name: 'Test'});
await User.findById(entry._id);
console.log('done');
}
run(); tsconfig
|
@IslandRhythms thanks for response, I created a new project and i used your snippet, and still get the same error but on schema only same code in above comment import * as mongoose from 'mongoose';
import { UserDocument, UserModel, UserSchema, UserObject } from '../interfaces/mongoose.gen'
const UserSchema: UserSchema = new mongoose.Schema({
name: String
});
const User = mongoose.model<UserDocument, UserModel>('User', UserSchema);
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const entry = await User.create({name: 'Test'});
await User.findById(entry._id);
console.log('done');
}
run(); package.json "dependencies": {
"mongoose": "^6.3.3"
},
"devDependencies": {
"mongoose-tsgen": "^9.0.5",
"nodemon": "^2.0.16",
"ts-node": "^10.7.0",
"typescript": "^4.6.4"
} same tsconfig {
"ts-node": {
"transpileOnly": true,
"files": true
},
"compilerOptions": {
"moduleResolution": "Node",
"outDir": "dist",
"allowSyntheticDefaultImports": true,
"declaration": false,
"removeComments": true,
"noUnusedLocals": false,
"newLine": "lf",
"noImplicitAny": true,
"pretty": true,
"noEmitOnError": true
},
"exclude": ["node_modules/**"]
} |
It must be something with your setup, I can't reproduce it on my end. |
Does it also happen when transpiling with tsc? Does it only happen in vscode? Which typescript version do you use in vscode? Which in your project? What happens when you update typescript? What when you update vscode? |
Yes, i'm using webstorm but i tested it on vscode also i get same error, on
when running src/models/User.ts:4:52 - error TS2589: Type instantiation is excessively deep and possibly infinite.
4 const UserSchema: UserSchema = new mongoose.Schema({
~
5 name: String
~~~~~~~~~~~~~~
6 });
~ heres the new project that contains the code snippet above and it produces the problem npm i && npx mtgen |
By using mongoose v6.3.1 the error will disappear for now. |
I downloaded your zip and ran it and still can't reproduce, it's something with your setup. |
Hello @IslandRhythms ! |
Got it |
Hello @HamoBoker, @jainil, @francescov1! |
Thanks for the ping @mohammad0-0ahmad, I'll look into this over the weekend! |
@HamoBoker This incompatibility is turning out to be a bit tougher to uncover than I expected. For now, you can continue using mongoose-tsgen with the @mohammad0-0ahmad Any idea on the expected timeline for your PR #11563. This PR removes the need for mongoose-tsgen, so depending on when it gets merged it may not be worth trying to fix the issue in mongoose-tsgen. |
@francescov1 sorry for that, I don't really know when it will be exactly merged, but @vkarpov15 said it will be shipped with the next minor release "6.4.0" |
Ok I'll stick with this solution for now Thank you guys for your great work, I really appreciate it |
@francescov1 thanks for looking into this and thanks for the lib, mongoose-tsgen is 👍 . You're right that the I really like this But, again, this sort of TypeScript bug is very hard to diagnose. We'll keep this open for the future, and consider pulling in the |
@vkarpov15 Thanks for checking this out, too bad there are not any obvious fixes. Sounds like the |
@vkarpov15 Can we expect this to be resolved by the Mongoose team, or is this is an issue with mongoose-tsgen? Would like to try getting it resolved soon since its a breaking issue for many users. I havent had any luck fixing it yet, but not sure if I should be focusing on fixing it from my end or from the Mongoose types. Also just finding it hard to track down the root cause since the error is so generic. |
@francescov1 try to override LeanDocument helper type, I think this issue is related to the changes made on that. |
@francescov1 as far as I can tell, this is an issue with mongoose-tsgen. We've been trying to improve the mongoose-tsgen type output, but haven't been able to fix it. |
I just reviewed this again, it seems the issue has been resolved as of Mongoose v6.4.1 (so it only affects Mongoose 6.3.2 - 6.4.0). I think we can close this @HamoBoker @vkarpov15 ? |
Yes @francescov1 , and sorry i forgot to close it. Thank you for the amazing work 💙 |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
i'm generating interfaces using mongoose-tsgen and everything works fine in mongoose <=6.3.1, but on v6.3.2 or v6.3.3 i get this ts error
TS2589: Type instantiation is excessively deep and possibly infinite
, also im not using@types/mongoose
If the current behavior is a bug, please provide the steps to reproduce.
await SomeModel.findById(id)
you can test example code in mongoose-tsgen
tsconfig.json
What is the expected behavior?
ts build without errors
Thank you so much for you great work
The text was updated successfully, but these errors were encountered: