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

1

6

error message after transpiling code below:

[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)

Starnes answered 11/6, 2015 at 7:50 Comment(0)
S
17

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)];
    }
Starnes answered 11/6, 2015 at 8:24 Comment(1)
Did the exact same thing and was sat there stairing at it for about 20 minutes wondering...Ap

© 2022 - 2024 — McMap. All rights reserved.