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)
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.
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!
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)];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With