【问题标题】:Unable to resolve signature of property decorator when called as an expression作为表达式调用时无法解析属性装饰器的签名
【发布时间】:2021-07-06 18:21:02
【问题描述】:
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)

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

【问题讨论】:

    标签: typescript graphql typegraphql class-validator


    【解决方案1】:

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

    import { IsEmail, IsEmpty, IsPhoneNumber, Length } from "class-validator";
    
    @Field()
    @IsEmail()
    email?: string;
    
    @Field()
    @Length(1, 20)
    @IsPhoneNumber()
    phoneNumber?: string;
    
    @IsEmpty()
    password?: string
    

    【讨论】:

    • 天哪,我觉得自己好笨。不过谢谢!
    • 没关系,我不知道有谁没有遇到过这种自制的问题。 ?不客气。 ?
    猜你喜欢
    • 2019-04-18
    • 2020-01-30
    • 2016-07-26
    • 2016-10-08
    • 2018-12-03
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 2016-04-02
    相关资源
    最近更新 更多