We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
8.0.2
18.x
6.x
5.2.2
When i use BigInt type in mongoose schema, i cannot pass typecheck and assign BigInt value to it's property.
export const affiliateSchema = new Schema({ balance: { type: BigInt, default: BigInt(0) }, }); const AffiliateModel = model("Affiliate", affiliateSchema); AffiliateModel.findOne({})!.then(modelValue => { modelValue.balance = 123n; });
No type error here.
The text was updated successfully, but these errors were encountered:
Currently i can fix it with a hacky type like this
export type AffiliateSchema = Omit<InferSchemaType<typeof affiliateSchema>, 'balance'> & { balance: bigint; };
Sorry, something went wrong.
Workaround is to do type: 'BigInt' in your schema as follows:
type: 'BigInt'
import mongoose from 'mongoose'; export const affiliateSchema = new mongoose.Schema({ balance: { type: 'BigInt', default: BigInt(0) }, }); const AffiliateModel = mongoose.model("Affiliate", affiliateSchema); AffiliateModel.findOne({}).orFail().then(modelValue => { modelValue.balance = 123n; });
types: handle using BigInt global class in schema definitions
fc635bf
Fix #14147
Merge pull request #14160 from Automattic/vkarpov15/gh-14147
2c8b6ab
Successfully merging a pull request may close this issue.
Prerequisites
Mongoose version
8.0.2
Node.js version
18.x
MongoDB server version
6.x
Typescript version (if applicable)
5.2.2
Description
When i use BigInt type in mongoose schema, i cannot pass typecheck and assign BigInt value to it's property.
Steps to Reproduce
Expected Behavior
No type error here.
The text was updated successfully, but these errors were encountered: