TypeScript Compilation Error Unable to invoke an expression whose type does not have a call signature

The code below is dragging me with gulp of this error:

[tsc]> C: /Workarea/MyFirstAngular/src/enum/msg.ts (35,33): error TS2349: Unable to invoke an expression whose type does not have a call signature. TypeScript failed to compile: Error: tsc command completed with code: 2

module MessageUtil { enum Morning { "Good Morning", "Great to see you!", "Good day.", "Lovely day today, isn't it?", "What 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 anyone know what my exact mistake is?

Same Thing worked once, but after several changes, it no longer compiles.

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

+6
source share
1 answer

Guys who have the same error message -> Check the syntax code

Found my mistake. 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)]; } 

Must be:

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

Source: https://habr.com/ru/post/988899/


All Articles