【问题标题】:Error TS2339: Property 'name' does not exist on type 'Function'错误 TS2339:“功能”类型上不存在属性“名称”
【发布时间】:2018-08-07 18:51:07
【问题描述】:

我有以下功能:

export function output(functions: Function[], inputs: unknown[]) {
    for (let func of functions) {
        console.log(`=== ${func.name} ===`);
        for (let input of inputs) {
            console.log(`"${input}"\t-> ${func(input)}`);
        }
        console.log();
    }
}

它工作正常。但是 tsc 编译器在这一行抱怨:

console.log(`=== ${func.name} ===`);

说:

错误 TS2339:“函数”类型上不存在属性“名称”。

导致问题的原因是什么?

【问题讨论】:

    标签: typescript


    【解决方案1】:

    我能够重现此问题。看起来定义函数接口的 lib.d.ts 文件没有“名称”作为属性。

    请参阅Typescript Issue 6623,它有一个解决方法。

    接口 Function 上的 name 属性在lib.es6.d.ts 中定义。如果 你用--target ES6 编译你应该看到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 2019-09-13
      • 2019-01-21
      • 2016-08-13
      • 2017-12-20
      • 2016-11-14
      相关资源
      最近更新 更多