-
-
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
Issues with Decimal128 type #12431
Comments
What are you doing to print that result? |
A simple |
maybe related to #12352? |
I think so |
I've also tried digging down TS and it seems that |
for context, what version of tsc is used to build and what version of typescript is used in vscode? ( |
I use the Workspace Version in VSCode, so it's 4.7.4 for both VSCode and tsc |
Note: the following is outdated information, see update at the end of comment
type ObtainSchemaGeneric<TSchema, alias extends 'EnforcedDocType' | 'M' | 'TInstanceMethods' | 'TQueryHelpers' | 'TVirtuals' | 'TStaticMethods' | 'TPathTypeKey' | 'DocType'> =
TSchema extends Schema<infer EnforcedDocType, infer M, infer TInstanceMethods, infer TQueryHelpers, infer TVirtuals, infer TStaticMethods, infer TPathTypeKey, infer DocType>
? {
EnforcedDocType: EnforcedDocType;
M: M;
TInstanceMethods: TInstanceMethods;
TQueryHelpers: TQueryHelpers;
TVirtuals: TVirtuals;
TStaticMethods: TStaticMethods;
TPathTypeKey: TPathTypeKey;
DocType: DocType;
}[alias]
: unknown;
type InferSchemaType<SchemaType> = ObtainSchemaGeneric<SchemaType, 'DocType'> ;
const Schema2 = new Schema({ // correct 8th generic (DocType)
createdAt: { type: Date, required: true },
decimalValue: { type: Schema.Types.Decimal128, required: true }
});
const t = {} as InferSchemaType<typeof Schema2>; // somehow has a modified DocType
type ObtainDocType<TSchema> =
TSchema extends Schema<any, any, any, any, any, any, any, infer DocType>
? DocType
: unknown;
type InferSchemaType<SchemaType> = ObtainDocType<SchemaType>;
const Schema2 = new Schema({ // correct 8th generic (DocType)
createdAt: { type: Date, required: true },
decimalValue: { type: Schema.Types.Decimal128, required: true }
});
const t = {} as InferSchemaType<typeof Schema2>; // DocType is returned without modification @Uzlopak @vkarpov15 @IslandRhythms what do you think about that? Update: after some more testing after #12450 (comment) it seems like |
I've tried to add/remove conditions to I don't understand why without this condition everything works, and adding it breaks my use case |
I took a look and confirmed that this issue was fixed in 6.7.0 with #12352. I added a test case that covers the issue described in OP and it is passing. |
Prerequisites
Mongoose version
6.6.1
Node.js version
18.2.0
MongoDB server version
5.x
Description
Adding a field to a Mongoose Schema with the type
Schema.Types.Decimal128
breaks all the typings ofmodel
, including the ones of the other fields of the Mongoose Schema.Make sure to use a version of Typescript < 4.8.x due to the fact that otherwise the build breaks.
Steps to Reproduce
For reference this is the
tsconfig.json
that I used to compileAs expected
TestModel
has the following typeIf we change our schema just a little bit, introducing
Schema.Types.Decimal128
it breaks every type.This results in
It seems that adding the Decimal128 unpacks every type in the Schema.
Expected Behavior
It should simply be something like:
The text was updated successfully, but these errors were encountered: