下面的代码让我通过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);
}
}
}
有谁知道我的确切错误是什么?
我的设置:-IDEA 14 -Node.js -Gulp -gulp-tsc -gulp-connect(用于Livereload)
有相同错误消息的人 - >检查您的代码语法
发现我的错。这不是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)]; }
应该:
private getRandomElementOfEnum(e : any):string{
var length:number = Object.keys(e).length; // <--- WITHOUT ()
return e[Math.floor((Math.random() * length)+1)];
}