Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript Compile Error Cannot invoke an expression whose type lacks a call signature

the code below get me by transpiling it with gulp this error:

[tsc] > C:/Workarea/MyFirstAngular/src/enum/msg.ts(35,33): error TS2349: Cannot invoke an expression whose type lacks a call signature. Failed to compile TypeScript: Error: tsc command has exited with code:2

module MessageUtil {
    enum Morning {
    "Good Morning",
    "Great to see you!",
    "Good day.",
    "Lovely day today, isn't it?",
    "What's up?",
    "Nice to meet you",
}
}
    export class MessageData {
        private getRandomElementOfEnum(e : any):string{
            var length:number = Object.keys(e).length();  //<-- This is Line 35
            return e[Math.floor((Math.random() * length)+1)];
        }
        public getRandMorning():string {
            return this.getRandomElementOfEnum(Morning);
        }
    }
}

Does anybody know what's my exact fault?

My Setup: -IDEA 14 -Node.js -Gulp -gulp-tsc -gulp-connect (for Livereload)

like image 399
Pascal Avatar asked Jun 11 '15 07:06

Pascal


People also ask

Does TS have a no call signature?

Type 'X' has no call signatures" TypeScript error occurs when we try to call a type that isn't a function, or is typed as something else, as a function. To solve the error, make sure you're calling a function and it is typed as a function. Here is an example of how the error occurs.

What is a call signature TypeScript?

In TypeScript we can express its type as: ( a : number , b : number ) => number. This is TypeScript's syntax for a function's type, or call signature (also called a type signature). You'll notice it looks remarkably similar to an arrow function—this is intentional!


1 Answers

Guys who have same error message --> Check your Code-Syntax

Found my fault. This is not Java.

 private getRandomElementOfEnum(e : any):string{
      var length:number = Object.keys(e).length();  //<-- This is Line 35
      return e[Math.floor((Math.random() * length)+1)];
 }

Should be:

    private getRandomElementOfEnum(e : any):string{
        var length:number = Object.keys(e).length;  // <--- WITHOUT ()
        return e[Math.floor((Math.random() * length)+1)];
    }
like image 69
Pascal Avatar answered Nov 05 '22 02:11

Pascal