当作为表达式调用时无法解析 属性 装饰器的签名

Unable to resolve signature of property decorator when called as an expression

import { isEmail, isEmpty, isPhoneNumber, Length } from "class-validator"
import { Field, InputType } from "type-graphql";

@InputType()
export class RegisterInput {
    @Field()
    @Length(2, 15, { message: "Username Must Be At Least 2 characters" })
    username?: string;

    @Field()
    @isEmail()
    email?: string;

    @Field()
    @Length(1, 20)
    @isPhoneNumber()
    phoneNumber?: string;

    @isEmpty()
    password?: string

}

问题是@isEmail() 和@isPhoneNumber() 以及@isEmpty() 抛出相同的错误:

Unable to resolve signature of property decorator when called as an expression.
  This expression is not callable.
    Type 'Boolean' has no call signatures.ts(1240)

请帮帮我,我整天都被这个错误困住了

你必须用大写字母写那些Decorators。 TypeScript 区分大小写:

import { IsEmail, IsEmpty, IsPhoneNumber, Length } from "class-validator";

@Field()
@IsEmail()
email?: string;

@Field()
@Length(1, 20)
@IsPhoneNumber()
phoneNumber?: string;

@IsEmpty()
password?: string

对于通过谷歌搜索错误消息来到这里的人。

我遇到这个错误是因为我从 .js 文件导入装饰器。将其转换为 TypeScript 为我解决了这个问题。

你的问题是因为你试图通过在它的末尾添加 () 来调用 class 装饰器 (@InputType())

相反,你应该 @InputType

我的问题是我不小心在装饰器后面添加了一个;

@minimumValue("quantity", 5);
async getItems(): Promise<Item[]> {
...

这导致 TS1240: Unable to resolve signature of property decorator when called as an expression.

所以正确的语法是没有 ;:

@minimumValue("quantity", 5)
async getItems(): Promise<Item[]> {
...