【发布时间】:2021-07-29 22:04:09
【问题描述】:
大家好,我是 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;
}
我的 config.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,
}
}
【问题讨论】:
-
您能展示一下您是如何尝试使用这些装饰器的吗?没看到使用,error和config都没用
-
也许你没有从类验证器库中导入这些装饰器
-
请附上您的 dto 代码
标签: node.js typescript nestjs class-validator ecmascript-2017