我正在使用这个美妙的库:https ://www.npmjs.com/package/ts-mixer
整个回溯如下所示:
(node:22654) UnhandledPromiseRejectionWarning: Error: A circular dependency has been detected (property key: "firstName"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").
at SchemaObjectFactory.createNotBuiltInTypeReference (/Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:212:19)
at SchemaObjectFactory.mergePropertyWithMetadata (/Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:143:25)
at /Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:79:35
at Array.map (<anonymous>)
at SchemaObjectFactory.extractPropertiesFromType (/Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:78:52)
at SchemaObjectFactory.exploreModelSchema (/Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:92:41)
at /Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:33:36
at Array.map (<anonymous>)
at SchemaObjectFactory.createFromModel (/Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/services/schema-object-factory.js:20:45)
at exploreApiParametersMetadata (/Users/albert/Documents/projects/albert/rlx/node_modules/@nestjs/swagger/dist/explorers/api-parameters.explorer.js:33:55)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:22654) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22654) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
注册通用用户.dto.ts
export class RegisterCommonUserDto {
@decorate(ApiProperty())
@decorate(IsNotEmpty())
@decorate(IsString())
firstName: string;
// @decorate(ApiProperty())
@decorate(IsNotEmpty())
@decorate(IsString())
lastName: string;
// @decorate(ApiProperty({enum: EUserRoleName}))
@decorate(IsNotEmpty())
@decorate(IsEnum(EUserRoleName))
roleName: EUserRoleName;
// @decorate(ApiProperty())
@decorate(IsNotEmpty())
@decorate(IsPhoneNumber())
phoneNumber: string;
// @decorate(ApiProperty())
@decorate(IsNotEmpty())
@decorate(IsEmail())
email: string;
}
注册用户.dto.ts
export class RegisterUserDto extends Mixin(
RegisterFighterDto,
RegisterCommonUserDto,
RegisterLocationProviderDto,
) {}
方法:
@Post('register')
public async registerUser(@Body() registerUserDto: RegisterUserDto): Promise<any> {
// code
}
什么可能导致问题?它肯定与@ApiProperty
被包裹的装饰器有关decorate
,因为当我注释掉该行时,错误消失了。但在那种情况下,装饰器不会被继承,这就是使用 ts-mixer 库的全部意义所在。
编辑:
有任何想法吗?
编辑:
这些库是不兼容的还是什么?