Dan McCoy
Dan McCoy

Reputation: 405

Why can't TypeScript find name 'Express'?

I'm starting an express application using TypeScript.

Here's the code in app.ts:

import express = require("express");

let app: Express = express();

I have installed Express using

npm install --save express

And I've installed @types/express using:

npm install --save @types/express

I'm using Visual Studio Code (1.10.2). When I hover over the express() function, intellisense suggests that it returns an object of type "Express". So, I've declared the "app" variable as that type, but VS Code puts a red squiggly under it and complains it "cannot find name 'Express'".

Why can't it find it? Or is that the wrong type? If so, why does the intellisense suggest it?

Upvotes: 2

Views: 2549

Answers (1)

Dan McCoy
Dan McCoy

Reputation: 405

It would appear the variable should actually be of type express.Application.

let app: express.Application = express();

Upvotes: 4

Related Questions