Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot invoke an expression whose type lacks a call signature. Type 'typeof ""' has no compatible call signatures React TypeScript

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'
...
componentWillMount() {
    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 compatible 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 = {}
        ...
like image 670
Ogglas Avatar asked Dec 03 '25 14:12

Ogglas


2 Answers

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.

like image 70
Sebastian Sebald Avatar answered Dec 06 '25 03:12

Sebastian Sebald


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

Wrong:

import * as cache from './ScriptCache'

Correct:

import cache from './ScriptCache'
like image 38
Ogglas Avatar answered Dec 06 '25 04:12

Ogglas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!