我正在尝试将三个脚本从 Javascript 转换为 TypeScript。这些脚本可以在此 gist 中找到.然而,我确实有一个错误,我无法摆脱。请注意,这是我的第一个 React 和 TypeScript 项目,所以我很容易错过一些明显的东西。我正在使用 .tsx
文件和 TypeScript 2.1。
在文件中:GoogleApiComponent.tsx
import * as cache from './ScriptCache'
...
componentWillMount() {
this.scriptCache = cache({ <--Error TS2349 here
google: GoogleApi({
apiKey: apiKey,
libraries: libraries
})
});
}
给我这个错误:
Cannot invoke an expression whose type lacks a call signature. Type 'typeof "ScriptCache"' has no compatible call signatures.
ScriptCache.tsx
看起来像这样:
let counter = 0;
let scriptMap = new Map();
export const ScriptCache = (function (global: any) {
return function ScriptCache(scripts: any) {
const Cache: any = {}
...
最佳答案
看起来你输入的不正确:)
请尝试像这样导入它 import cache from './ScriptCache'
。如果您只是使用要点中的代码,缓存也会默认导出。
如果这不起作用,请尝试 import { ScriptCache as cache } from './ScriptCache'
。您不需要 as
语法。这只是为了让您不必更改变量名称。
关于javascript - 无法调用其类型缺少调用签名的表达式。输入 'typeof ""' 没有兼容的调用签名 React TypeScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43610798/