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 behavior?
There are several issues with official types:
Query is declared as an interface, so I cannot anymore do
import{Query}from'mongoose';constmaybeQuery={};console.log(maybeQueryinstanceofQuery)// 'Query' only refers to a type, but is being used as a value here
Fix: Query should be declared as class not as interface
Query.where doesn't have signature for passing object in where but I can do this in js:
// Post is a modelPost.where({})// TSError: Argument of type '{}' is not assignable to parameter of type 'string'.Post.where()// TSError: Expected 1-2 arguments, but got 0.Post.where({$and: [{isActive: true},{id: 1}]})// TSError: Argument of type '{ $and: ({ isActive: boolean; } | { id: number; })[]; }' is not assignable to parameter of type 'string'
all these are valid cases in pure js and perfectly worked with @types/mongoose
Do you want to request a feature or report a bug?
bug
What is the current behavior?
There are several issues with official types:
Query
is declared as an interface, so I cannot anymore doBut I can do this in pure js
Fix:
Query
should be declared asclass
not asinterface
Query.where
doesn't have signature for passing object inwhere
but I can do this in js:all these are valid cases in pure js and perfectly worked with
@types/mongoose
Fix: add method overload for
where
No way to define custom Query methods added by a plugin (exist as a separate issue [types] Support custom Query Method types #9850)
If the current behavior is a bug, please provide the steps to reproduce.
npm i typescript mongoose
index.ts
and put inside every example from the descriptionWhat is the expected behavior?
Expected to not have TypeScript errors
What 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: