最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cannot invoke an expression whose type lacks a call signature. Type 'typeof ""' h

programmeradmin3浏览0评论

I'm trying to convert three scripts from Javascript to TypeScript. The scripts can be found in this gist. I do however have one error left that I can't get rid of. Please note that this is my first React and TypeScript project so I can easily have missed something obvious. I'm using .tsx files and TypeScript 2.1.

In the file: GoogleApiComponent.tsx

import * as cache from './ScriptCache'
...
ponentWillMount() {
    this.scriptCache = cache({ <--Error TS2349 here
        google: GoogleApi({
            apiKey: apiKey,
            libraries: libraries
        })
    });
}

Gives me this error:

Cannot invoke an expression whose type lacks a call signature. Type 'typeof "ScriptCache"' has no patible call signatures.

ScriptCache.tsx looks like this:

let counter = 0;
let scriptMap = new Map();

export const ScriptCache = (function (global: any) {
    return function ScriptCache(scripts: any) {
        const Cache: any = {}
        ...

I'm trying to convert three scripts from Javascript to TypeScript. The scripts can be found in this gist. I do however have one error left that I can't get rid of. Please note that this is my first React and TypeScript project so I can easily have missed something obvious. I'm using .tsx files and TypeScript 2.1.

In the file: GoogleApiComponent.tsx

import * as cache from './ScriptCache'
...
ponentWillMount() {
    this.scriptCache = cache({ <--Error TS2349 here
        google: GoogleApi({
            apiKey: apiKey,
            libraries: libraries
        })
    });
}

Gives me this error:

Cannot invoke an expression whose type lacks a call signature. Type 'typeof "ScriptCache"' has no patible call signatures.

ScriptCache.tsx looks like this:

let counter = 0;
let scriptMap = new Map();

export const ScriptCache = (function (global: any) {
    return function ScriptCache(scripts: any) {
        const Cache: any = {}
        ...
Share Improve this question edited Apr 25, 2017 at 13:00 Ogglas asked Apr 25, 2017 at 12:34 OgglasOgglas 70.1k42 gold badges376 silver badges473 bronze badges 2
  • 1 Please give a full example. This could also be caused by how you import/export your modules + on what line the error occurs. – Sebastian Sebald Commented Apr 25, 2017 at 12:57
  • @SebastianSebald You were right, it was an import error! Thank you so much! – Ogglas Commented Apr 25, 2017 at 13:04
Add a ment  | 

3 Answers 3

Reset to default 9

Looks like you're import is not correct :)

Please try to import it like this import cache from './ScriptCache'. If you just used the code from the gist the cache is also exported as default.

If this does not work, try import { ScriptCache as cache } from './ScriptCache'. You do not need the as syntax. This is just so you don't have to change the variable names.

Turned out to be an import error as suggested by @Sebastian Sebald.

Wrong:

import * as cache from './ScriptCache'

Correct:

import cache from './ScriptCache'

Same and slightly different for me:

Wrong:

import thing from './dependency'

Correct:

import { thing } from './dependency'

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论