You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
types / bug
What is the current behavior?
since 5.13.4 new genericModel({ properties }) does not work anymore when in an generic context (even if restricted to extend from a class with the properties)
If the current behavior is a bug, please provide the steps to reproduce.
// NodeJS: 16.6.0// MongoDB: 4.2-bionic (Docker)import*asmongoosefrom"mongoose";// [email protected]// when the "AnyKeys" in mongoose is replaced with this, it works// type AnyKeys<T> = { [P in keyof T]?: T[P] | any };classTesty{publicprop1!: string;publicprop2?: string;}// the following 2 functions should be the same in types, so they both have the errorfunctiontest1<UextendstypeofTesty>(arg1: mongoose.Model<mongoose.Document&InstanceType<U>>){constt=newarg1({prop2: "hello"});// error here}functiontest2<UextendsTesty>(arg1: mongoose.Model<mongoose.Document&U>){constt=newarg1({prop2: "hello"});// error here}// working, both of these blocks should be equal in typesconstsch=newmongoose.Schema({prop1: String,prop2: String});sch.loadClass(Testy);{constmodel: mongoose.Model<mongoose.Document<any,any>&InstanceType<typeofTesty>>=mongoose.model("testy1",sch);constt=newmodel({prop2: "hello"});}{constmodel: mongoose.Model<mongoose.Document<any,any>&Testy>=mongoose.model("testy2",sch);constt=newmodel({prop2: "hello"});}
Note: the new AnyKeys type is basically like the one existing already, but removed the need for Partial, because it directly integrates ?, and the | undefined part (from Partial) should not be needed anymore, because it already has | any
Error (for both mentioned times):
Argument of type '{ prop2: string; }' is not assignable to parameter of type 'Partial<{ [P in keyof (Document<any, any, any> & InstanceType<U>)]: any; }> & AnyObject'.
Type '{ prop2: string; }' is not assignable to type 'Partial<{ [P in keyof (Document<any, any, any> & InstanceType<U>)]: any; }>'.ts(2345)
What is the expected behavior?
to not give an error
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose 5.13.4 / 5.13.5
PS: because this took some time to find out and sometimes the types were too complex, #10525 came from it
The text was updated successfully, but these errors were encountered:
hasezoey
changed the title
[Types] "new generic({ options })" does not work anymore since 5.13.5
[Types] "new generic({ properties })" does not work anymore since 5.13.4
Aug 1, 2021
Thanks for finding this - apparently { [P in keyof T]?: T[P] | any } is different from Partial<{ [P in keyof T]: T[P] | any }>, although I haven't been able to figure out why. The below also fails:
Do you want to request a feature or report a bug?
types / bug
What is the current behavior?
since 5.13.4
new genericModel({ properties })
does not work anymore when in an generic context (even if restricted to extend from a class with the properties)Re: #10475
Commit introducing the issue: 060039d
If the current behavior is a bug, please provide the steps to reproduce.
Note: the new
AnyKeys
type is basically like the one existing already, but removed the need forPartial
, because it directly integrates?
, and the| undefined
part (fromPartial
) should not be needed anymore, because it already has| any
Error (for both mentioned times):
tsconfig:
Reproduction Repository & branch: https://github.com/typegoose/typegoose-testing/tree/mongooseNewIssue
Reproduction File: https://github.com/typegoose/typegoose-testing/blob/mongooseNewIssue/src/test.ts
What is the expected behavior?
to not give an error
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose 5.13.4 / 5.13.5
PS: because this took some time to find out and sometimes the types were too complex, #10525 came from it
The text was updated successfully, but these errors were encountered: