vitaly-t/pg-promise-demo

[TypeScript] Cannot invoke an expression whose type lacks a call signature!!!

AhmedBHameed opened this issue ยท 6 comments

By using the same example on your repo. here
https://github.com/vitaly-t/pg-promise-demo/blob/master/TypeScript/db/index.ts

I'm getting this Typescript error saying: [ts] Cannot invoke an expression whose type lacks a call signature. Type 'typeof pgPromise' has no compatible call signatures. [2349] !!!

import { IMain, IDatabase, IOptions } from "pg-promise";
import * as pgPromise from "pg-promise";

const pgp: IMain = pgPromise(); // Error pop up here!!

Using ES6 in tsconfig.json

Any idea?

What version of TypeScript are you using?

Must be something unique, because nobody else has that problem.

Hi @vitaly-t, Thank you for this lovely library. so the version is Version 3.2.2.
I fallback to require just to override this issue. But still wondering why is not accepted by typescript !!

Extra to that this is my tsconfig.json file

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "lib": ["es2015", "dom"],
    "sourceMap": true,
    "outDir": "./dist",
    "removeComments": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "moduleResolution": "node",
    "baseUrl": ".",
    "paths": {
      "*": ["node_modules/*", "src/Types/*"]
    },
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}

Thank you.

I've seen this "esModuleInterop": true causing problems in the past. Try removing it ;)

Anyhow, pg-promise builds fine with the default settings, it is something in your custom config that breaks.

That solved my problem. Thank you.

just do

import pgPromise from "pg-promise";

Otherwise you'll have to do pgPromise.pgPromise

This is standard TypeScript configuration flag - esModuleInterop. When set to true, the import syntax is import pgPromise from 'pg-promise', and when false, which is the default, the syntax is import * as pgPromise from 'pg-promise'.

The library simply gives you example of what is the default TypeScript configuration.