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?
Bug
What is the current behaviour?
I want to use the this type in the pre-save middleware I've added to my schema. But the this always resolves to any with Typescript. I normally read through your index.d.ts file and I know the this type is defined, so I don't like importing extra things from mongoose because of the extra space since it's already there.
The pre method's generic argument is set to be this HydratedDocument you pass other type arguments to.
The TInstanceMethods type defaults to any, and in the HydratedDocument absorbs the other types and everything resolves to any.
This is the case in many other places and I understand why any is used, but I want to ask if you can consider using unknown or {} for those types you expect to be an object in any case. Like the methods or query helpers. You already do this with the Model definition ⬇️
If the current behaviour is a bug, please provide the steps to reproduce.
import{Schema}from"mongoose";typeIUserSchema={name: string;}constUserSchema=newSchema<IUserSchema>({name: {type: String}});UserSchema.pre("save",function(next){this.name;// Unsafe member access .name on an `any` valuenext();});
If you are using TypeScript, please include your tsconfig.json
Do you want to request a feature or report a bug?
Bug
What is the current behaviour?
I want to use the
this
type in the pre-save middleware I've added to my schema. But thethis
always resolves toany
with Typescript. I normally read through your index.d.ts file and I know thethis
type is defined, so I don't like importing extra things from mongoose because of the extra space since it's already there.The
pre
method's generic argument is set to be this HydratedDocument you pass other type arguments to.mongoose/types/index.d.ts
Lines 1194 to 1196 in 18cb0be
The
TInstanceMethods
type defaults toany
, and in theHydratedDocument
absorbs the other types and everything resolves toany
.This is the case in many other places and I understand why
any
is used, but I want to ask if you can consider usingunknown
or{}
for those types you expect to be an object in any case. Like the methods or query helpers. You already do this with the Model definition ⬇️mongoose/types/index.d.ts
Line 594 in 18cb0be
If the current behaviour is a bug, please provide the steps to reproduce.
If you are using TypeScript, please include your
tsconfig.json
What is the expected behaviour?
The
this
type to be properly typesWhat are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: