TypeScript 编译错误无法调用类型缺少调用签名的表达式
TypeScript Compile Error Cannot invoke an expression whose type lacks a call signature
下面的代码通过 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
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);
}
}
}
有人知道我到底错在哪里吗?
我的设置:
-想法 14
-Node.js
-Gulp
-gulp-tsc
-gulp-连接(用于 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)];
}
下面的代码通过 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
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);
}
}
}
有人知道我到底错在哪里吗?
我的设置: -想法 14 -Node.js -Gulp -gulp-tsc -gulp-连接(用于 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)];
}