Schema Error while running backend server nestjs/angular

I finally came here after putting lot of efforts but no success. I learn Nestjs/Angular/MongoDB. So far I got success running both Angular server & Nestjs server simaltaneously. But I get huge list of errors 147 (mostly related to schema) when I initialize mongoDB with them. Everything seems fine, connection between mongdb compass & atlas work perfectly.
grateful for your advise

following an error.

[8:16:58 PM] Starting compilation in watch mode...

node_modules/@nestjs/mongoose/dist/factories/schema.factory.d.ts:4:60 - error TS2315: Type 
'Schema' is not generic.

4     static createForClass<T = any>(target: Type<unknown>): mongoose.Schema<T>;
                                                         ~~~~~~~~~~~~~~~~~~
node_modules/@types/mongoose/index.d.ts:79:1 - error TS6200: Definitions of the following 
identifiers conflict with those in another file: DocumentDefinition, FilterQuery, 
UpdateQuery, NativeError, Mongoose, CastError, Collection, Connection, Error, QueryCursor, 
VirtualType, Schema, Subdocument, Array, DocumentArray, Buffer, ObjectId, Decimal128, Map, 
Aggregate, SchemaType, Document

79     declare module "mongoose" {
 node_modules/mongoose/index.d.ts:1:1
 1 declare module "mongoose" {
   ~~~~~~~
 Conflicts are in this file.

 node_modules/@types/mongoose/index.d.ts:226:14 - error TS2403: Subsequent variable 
 declarations must have the same type.  Variable 'SchemaTypes' must be of type 'typeof 
 Types', but here has type 'typeof Types'.

 226   export var SchemaTypes: typeof Schema.Types;
              ~~~~~~~~~~~

 node_modules/mongoose/index.d.ts:45:14
 45   export var SchemaTypes: typeof Schema.Types;
                 ~~~~~~~~~~~
 'SchemaTypes' was also declared here.

 node_modules/@types/mongoose/index.d.ts:822:24 - error TS2314: Generic type 
 'Query<ResultType, DocType, T>' requires 3 type argument(s).

 822     constructor(query: Query<T>, options: any);
                        ~~~~~~~~

 node_modules/@types/mongoose/index.d.ts:1013:19 - error TS2314: Generic type 
 'Query<ResultType, DocType, T>' requires 3 type argument(s).

 1013     pre<T extends Query<any> = Query<any>>(
                    ~~~~~~~~~~

 node_modules/@types/mongoose/index.d.ts:1013:32 - error TS2314: Generic type 
 'Query<ResultType, DocType, T>' requires 3 type argument(s).

 1013     pre<T extends Query<any> = Query<any>>(
                                 ~~~~~~~~~~

 node_modules/@types/mongoose/index.d.ts:1036:48 - error TS2314: Generic type 
 'Query<ResultType, DocType, T>' requires 3 type argument(s).

 1036     pre<T extends Document | Model<Document> | Query<any> | Aggregate<any>>(

I had the same error into Typescript + Express + Mongoose application. Try adding skipLibCheck: true option to your tsconfig.json. I found the solution here, it is was published just 2 days ago: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/33290#issuecomment-740513790

1 Like

Also you don’t need to use @types/mongoose since mongoose 5.11 was published with its own type definitions. Hope it helps. https://github.com/Automattic/mongoose/issues/9606#issuecomment-736710621

2 Likes