Nin*_*nja 12 typescript graphql class-validator typegraphql
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
}
Run Code Online (Sandbox Code Playgroud)
问题是 @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)
Run Code Online (Sandbox Code Playgroud)
请帮帮我,我一整天都被这个错误困扰了
小智 38
你必须用大写字母来书写这些装饰器。TypeScript 区分大小写:
import { IsEmail, IsEmpty, IsPhoneNumber, Length } from "class-validator";
@Field()
@IsEmail()
email?: string;
@Field()
@Length(1, 20)
@IsPhoneNumber()
phoneNumber?: string;
@IsEmpty()
password?: string
Run Code Online (Sandbox Code Playgroud)
Hug*_*hal 18
您可能需要将此属性添加到tsconfig.json
文件中的属性下compilerOptions
:
"experimentalDecorators": true
Run Code Online (Sandbox Code Playgroud)
感谢 Technical Rajni 提供的 YouTube 视频解决方案,请参见此处。
归档时间: |
|
查看次数: |
25275 次 |
最近记录: |