2017-07-14 111 views
0

我用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.

看起來好像我的定義文件不正確。如何解決這個問題?

回答

0

既然你對功能update默認的導出,你必須將其導入,如:

import update from 'react/lib/update'; 
+0

呀。這適用於'es6' js,而不是'typescript'。我解決了它。謝謝。這個問題應該關閉。 – novaline

+0

@novaline如果您解決了這個問題,考慮將其添加爲答案,以便將來的用戶可以從中受益。 – Saravana

相關問題