【问题标题】:Cannot invoke an expression whose type lacks a call signature.无法调用其类型缺少调用签名的表达式。
【发布时间】:2017-12-19 03:18:18
【问题描述】:

我使用react/lib/update 方法和typescript

我为它写了一个定义文件,像这样:

declare module 'react/lib/update' {
  export default function update<S>(value: S, spec: any): S;
}

并且,像这样使用它:

import * as update from 'react/lib/update';

但是tsc给我一个错误:

Cannot invoke an expression whose type lacks a call signature. Type 'typeof 'react/lib/update'' has no compatible call signatures.

看来我的定义文件不正确。如何解决?

【问题讨论】:

    标签: reactjs typescript typescript-typings typescript2.0


    【解决方案1】:

    由于您在函数update 上有一个默认导出,因此您必须像这样导入它:

    import update from 'react/lib/update';
    

    【讨论】:

      猜你喜欢
      • 2017-07-14
      • 2020-02-07
      • 1970-01-01
      • 2019-01-05
      • 2018-05-09
      • 2023-03-20
      • 2017-09-01
      • 2021-02-06
      • 2017-03-17
      相关资源
      最近更新 更多