TypeScript编译错误无法调用其类型缺少调用签名的表达式

Syn*_*oon 6 code-translation typescript

下面的代码让我通过gulp这个错误转发它:

[tsc]> C:/Workarea/MyFirstAngular/src/enum/msg.ts(35,33):错误TS2349:无法调用类型缺少调用签名的表达式.无法编译TypeScript:错误:tsc命令已退出,代码为: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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

有谁知道我的确切错误是什么?

我的设置:-IDEA 14 -Node.js -Gulp -gulp-tsc -gulp-connect(用于Livereload)

Syn*_*oon 17

有相同错误消息的人 - >检查您的代码语法

发现我的错.这不是 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)];
 }
Run Code Online (Sandbox Code Playgroud)

应该:

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

  • 是完全相同的事情,坐在那里楼梯约20分钟想知道... (2认同)