【问题标题】:ES2017 NEST JS @IsEmpty Unable to resolve signature of property decorator when called as an expression.This expression is not callable. is not emptyES2017 NEST JS @IsEmpty 在作为表达式调用时无法解析属性装饰器的签名。此表达式不可调用。不为空
【发布时间】: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


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    为了扩展 Juan 的答案,isNotEmpty 是来自class-valdiator 的内部使用检查,可以用作直接方法。 IsNotEmtpy(注意大写)是装饰器,应该和@一起使用来表示它是装饰器。

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 2019-04-18
      • 2020-01-30
      • 2016-07-26
      • 2016-10-08
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      相关资源
      最近更新 更多