LoginSignup
24
11

More than 5 years have passed since last update.

TypeScriptでexpressを使う際に出たエラーの解決法

Last updated at Posted at 2019-01-02

ネット上の記事では多くがimport * as express from 'express';とやっているが、自分の環境ではこれをやるとexpress()の箇所に以下のエラーが出てきた。

Cannot invoke an expression whose type lacks a call signature. Type 'typeof e' has no compatible call signatures.
// 型に呼び出しシグネチャがない式を呼び出すことはできません。

expressをデフォルトよりインポートしたら解決した。

これだとエラー

before.ts
import * as express from 'express';

const app = express();
// ここでエラー

これでエラーは解消

after.ts
import express from 'express';

const app = express();
// エラーは消え去った
// package.jsonには、devDependenciesとして
// "@types/express"も入れている
24
11
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
11