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

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


8

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

}

The thing is @isEmail() and @isPhoneNumber() and @isEmpty() throw the same error:

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)

Please help me out I’ve been stuck with this bug the whole day

5 Answers
5


32

You have to write those Decorators with a capital letter. TypeScript is case sensitive:

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

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

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

@IsEmpty()
password?: string

2

  • oh god, i feel so dumb. Thank you though !

    – Ninja

    Apr 11, 2021 at 13:53

  • 1

    Nevermind, I don't know anyone who did not run in such self made problems. 😉 You're welcome. 🙂

    – user6749601

    Apr 11, 2021 at 14:10


1

For people who come here by googling the error message.

I had this error because I was importing the decorator from a .js file. Converting it to TypeScript resolved the issue for me.


1

My problem was that I accidentally added a ; after the decorator:

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

This results in TS1240: Unable to resolve signature of property decorator when called as an expression..

So the correct syntax is without the ;:

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


0

You might need to add this property to your tsconfig.json file, under the compilerOptions property:

"experimentalDecorators": true

Kudos to Technical Rajni for the youtube video solution, here.


-1

your problem is because you tried to invoke the class decorator by adding () at the end of it (@InputType())

instead you should just do @InputType



Leave a Reply

Your email address will not be published. Required fields are marked *