[英]NestJs ParseEnumPipe can't be resolve
I am using the NestJs framework (love it by the way) and I want to check the incoming data so it conforms with an Enum in Typscript.我正在使用 NestJs 框架(顺便说一下喜欢它),我想检查传入的数据,使其符合 Typscript 中的枚举。 So I have the following:
所以我有以下内容:
enum ProductAction {
PURCHASE = 'PURCHASE',
}
@Patch('products/:uuid')
async patchProducts(
@Param('uuid', ParseUUIDPipe) uuid: string,
@Body('action', ParseEnumPipe) action: ProductAction,
) {
switch(action) {
... code
}
The weird thing is that when I run this code, the first pipe gets compiled奇怪的是,当我运行这段代码时,第一个管道被编译了
2022-07-21 16:53:51 [error] [ExceptionHandler] Nest can't resolve dependencies of the ParseEnumPipe (?, Object). Please make sure that the argument Object at index [0] is available in the FriendsModule context.
What I am doing wrong?我做错了什么?
您应该使用@Body('action', new ParseEnumPipe(ProductAction)) action: ProductAction
因为枚举不会直接反映给 Nest 来读取其元数据,并且因为 Nest 试图弄清楚如何在真正注入Object
时应该注入枚举。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.