[英]ES2017 NEST JS @IsEmpty Unable to resolve signature of property decorator when called as an expression.This expression is not callable. is not empty
大家好,我是 Nest JS 的新手,我尝试添加 dto 验证器,但例如当我尝试添加 isNotEmpty 或 Max 编译器时,会显示此错误:
当作为表达式调用时,无法解析属性装饰器的签名。 此表达式不可调用。
DTO:
import { Transform, Type } from 'class-transformer';
import { IsInt, isNotEmpty } from 'class-validator';
export class MessagesQueryDTO {
@isNotEmpty()
@IsInt()
@Type(() => Number)
readonly limit: number;
@isNotEmpty()
@Type(() => Number)
@IsInt()
readonly skip: number;
}
我的配置.json
{
"exclude": ["**/*spec.ts"],
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"esModuleInterop": true,
}
}
isNotEmpty 装饰器应该是 IsNotEmpty,首字母大写。
为了扩展 Juan 的答案, isNotEmpty
是class-valdiator
内部使用的检查,可以用作直接方法。 IsNotEmtpy
(注意大写)是装饰器,应该和@
一起使用来表示它是装饰器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.