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
circular constraint issue #13129
Comments
I'm using NestJS with a mongoose package that probably needs to be updated: https://github.com/nestjs/mongoose As this could be the issue I'm going to wait until a new version of it has been released and come back here if the issue hasn't been resolved. |
Can you please provide a more complete code sample, like what your schema definitions look like? |
Mongoose version: 7.0.2 I've also been getting this issue, and might be able to provide some more insight. An example of the offending code w/ schema definitions:
Compiling the project results in the following error, but only when used with the --build flag:
Avoiding the --build flag fixes the issue, though I was able to use the --build flag before I switched to automatic schema type inference. For those that do need the perks of typescript's build flag and don't want to maintain separate schema interfaces, I can see this being an issue. |
@davidvorona what is |
This happened with very simple models as well, but here's the whole purchases array:
|
I'm still unable to repro, below script compiles fine with import { Schema, model, InferSchemaType } from "mongoose";
const DisbursementSchema = new Schema({
paymentId: {
type: String,
required: true
},
paymentDate: {
type: Date,
required: true
},
buyer: {
id: {
type: Schema.Types.ObjectId,
ref: "user"
},
username: {
type: String
},
email: {
type: String
},
city: {
type: String
},
state: {
type: String
},
deliveryZip: {
type: String
},
},
seller: {
id: {
type: Schema.Types.ObjectId,
ref: "user"
},
username: {
type: String
},
email: {
type: String
},
createDate: {
type: Date
}
},
purchases: [
{
ledgerId: {
type: Schema.Types.ObjectId,
ref: "ledger",
required: true
},
item: {
name: {
type: String
},
type: {
type: String,
//enum: itemTypes
}
},
purchasePrice: {
type: Number
},
quantity: {
type: Number
},
shipping: {
cost: {
type: Number
},
// 0b01 isCombined, 0b10 isInternational, 0b11 isCombined/isInternational
strategy: {
type: Number
}
},
taxPrice: {
type: Number
},
transactionFee: {
percent: {
type: Number
},
discount: {
type: Number
},
total: {
type: Number
}
},
processingFee: {
percent: {
type: Number
},
fixed: {
type: Number
},
total: {
type: Number
}
},
foreignTransactionFee: {
percent: {
type: Number
},
total: {
type: Number
}
},
groupModeratorFee: {
percent: {
type: Number
},
total: {
type: Number
}
},
paymentType: {
type: String
},
purchaseDate: {
type: Date
},
netPayment: {
type: Number
},
disbursementInfo: {
id: {
type: Schema.Types.ObjectId
},
isDisbursed: {
type: Boolean,
default: false,
required: true
},
date: {
type: Date
},
by: {
type: String
},
eWallet: {
entity: {
type: String
},
account: {
type: String
},
fullName: {
type: String
},
bankAccountNumber: {
type: Number
},
routingNumber: {
type: Number
}
}
},
exceptionInfo: {
id: {
type: Schema.Types.ObjectId
},
type: {
type: String,
//enum: exceptionTypes
},
date: {
type: Date
},
by: {
type: String
}
}
}
]
});
export type DisbursementModel = InferSchemaType<typeof DisbursementSchema>;
DisbursementSchema.index({ "paymentId": 1, "seller.id": 1 }, { unique: true });
export default model("disbursement", DisbursementSchema); Given that compilation only fails with For example, the tsconfig.json we're using is this one:
|
I found that setting
But what should I do if I wanna have it set to |
@vkarpov15 I noticed same circular error in version 7. TL;DR: it's because of Simple example:
import { InferSchemaType, Schema } from 'mongoose';
const schema = new Schema({});
export type LocalityRaw = InferSchemaType<typeof schema>; Output:
{
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"outDir": "dist",
"incremental": true
},
"include": [
"src/**/*"
]
} But if I change |
FWIW, I tried setting |
@Jokero I've confirmed that I get the same error you see, I'm investigating to see if I can find a fix or workaround. |
…remental by deferring `ResolveSchemaOptions<>` Fix #13129
types(schema): avoid circular constraint in TSchemaOptions with --incremental by deferring `ResolveSchemaOptions<>`
Prerequisites
Mongoose version
7.0.0
Node.js version
16.14.2
MongoDB server version
4.4
Typescript version (if applicable)
4.9.5
Description
I get a compilation error when specifying the
Schema
inside aconnection.model
call.Steps to Reproduce
I have the following line of code in a typescript project:
When compiling the project, I get:
If I remove the
UserSchema
from the parameters like that:it works.
doing
skipLibCheck: true
also resolves the problem, but that's not sth I wanna do.Expected Behavior
This error should not happen.
The text was updated successfully, but these errors were encountered: