[nestjs] 解决mongoose类型冲突报错

568 阅读1分钟

安装依赖包

"@typegoose/typegoose": "^7.4.8",
"@types/mongoose": "^5.10.3",
"mongoose": "^5.11.17",
"nestjs-typegoose": "^7.1.38",

报错

node_modules/@types/mongoose/index.d.ts:3664:49 - error TS2314: Generic type 'Query<ResultType, DocType>' requires 2 type argument(s).

3664 callback?: (err: any, raw: any) => void): Query<any> & QueryHelpers;
~~~~~~~~~~

node_modules/@types/mongoose/index.d.ts:3666:49 - error TS2314: Generic type 'Query<ResultType, DocType>' requires 2 type argument(s).

3666 callback?: (err: any, raw: any) => void): Query<any> & QueryHelpers;

node_modules/mongoose/index.d.ts:1:1 - error TS6200: Definitions of the following identifiers conflict with those in another file: DocumentDefinition, FilterQuery, UpdateQuery, NativeError, Mongoose, SchemaTypes, ......

1 declare module 'mongoose' {
~~~~~~~

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

[下午9:21:03] Found 95 errors. Watching for file changes.

后来发现从github @types/mongoose里面找到答案: https://github.com/definitelytyped/definitelytyped/issues/49950

github.com/definitelyt…

直接移除 @types/mongoose 就好了。npm un @types/mongoose