guys. I'm using a provider(useFactory) to register mongoose-sequence plugin for my User Schema, but it doesn't work because of @type check. This is my module.
import { Module } from '@nestjs/common';
import { MongooseModule, getConnectionToken } from '@nestjs/mongoose';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { User, UserSchema } from './schema/user.schema';
import * as AutoIncrementFactory from 'mongoose-sequence';
import { Connection } from 'mongoose';
@Module({
imports: [
MongooseModule.forFeatureAsync([
{
name: User.name,
//schema: UserSchema,
useFactory: async (connection: Connection) => {
const schema = UserSchema;
const AutoIncrement = AutoIncrementFactory(connection);
schema.plugin(AutoIncrement, { inc_field: 'users' });
return schema;
},
inject: [getConnectionToken()],
},
]),
],
controllers: [UserController],
providers: [UserService],
exports: [UserService],
})
export class UserModule {}
When saved, the compiler throws the error:
src/user/user.module.ts:17:54 - error TS2345: Argument of type 'Connection' is not assignable to parameter of type 'Schema<any, Model<any, any, any, any, any>, {}, {}, {}, {}, DefaultSchemaOptions, { [x: string]: any; }>'.
Type 'Connection' is missing the following properties from type 'Schema<any, Model<any, any, any, any, any>, {}, {}, {}, {}, DefaultSchemaOptions, { [x: string]: any; }>': add, alias, childSchemas, clearIndexes, and 24 more.
17 const AutoIncrement = AutoIncrementFactory(connection);
~~~~~~~~~~
src/user/user.module.ts:18:25 - error TS2345: Argument of type 'void' is not assignable to parameter of type 'PluginFunction<User, Model<User, any, any, any, any>, any, any, any, any>'.
18 schema.plugin(AutoIncrement, { inc_field: 'users' });
If I uninstall this package @types/mongoose-sequence, it works, so how to fixed it if I want to keep @type check. thanks.