TypeScript 编译错误无法调用类型缺少调用签名的表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30774759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeScript Compile Error Cannot invoke an expression whose type lacks a call signature
提问by Synoon
the code below get me by transpiling it with gulp this error:
下面的代码通过使用 gulp 这个错误来转译它来得到我:
[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
[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);
}
}
}
Does anybody know what's my exact fault?
有谁知道我的确切错误是什么?
My Setup: -IDEA 14 -Node.js -Gulp -gulp-tsc -gulp-connect (for Livereload)
我的设置:-IDEA 14 -Node.js -Gulp -gulp-tsc -gulp-connect(用于 Livereload)
回答by Synoon
Guys who have same error message --> Check your Code-Syntax
有同样错误信息的人 --> 检查你的代码语法
Found my fault. This is notJava.
发现我的错。这不是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(); //<-- 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)];
}