首页 > 解决方案 > ES2017 NEST JS @IsEmpty 在作为表达式调用时无法解析属性装饰器的签名。此表达式不可调用。不为空

问题描述

大家好,我是 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,
  }
}

标签: node.jstypescriptnestjsclass-validatorecmascript-2017

解决方案


isNotEmpty 装饰器应该是 IsNotEmpty,首字母大写。


推荐阅读