【问题标题】:TypeScript Compile Error Cannot invoke an expression whose type lacks a call signatureTypeScript 编译错误无法调用类型缺少调用签名的表达式
【发布时间】:2015-08-26 19:01:19
【问题描述】:

下面的代码通过 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);
        }
    }
}

有人知道我的错吗?

我的设置: -想法 14 -Node.js -吞咽 -gulp-tsc -gulp-connect(用于 Livereload)

【问题讨论】:

    标签: typescript code-translation


    【解决方案1】:

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

    发现我的错。这不是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)];
        }
    

    【讨论】:

    • 做了同样的事情,然后坐在那里爬了大约 20 分钟,想知道......
    猜你喜欢
    • 2019-09-10
    • 2018-12-25
    • 2017-09-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 2017-04-16
    • 2017-02-03
    相关资源
    最近更新 更多