EternallyCurious
EternallyCurious

Reputation: 2415

Is it possible to include a NodeJS module in a TypeScript Project with "import"

I am converting my NodeJS + ExpressJS project to typescript and I got a Typescript definition for ExpressJS from https://github.com/borisyankov/DefinitelyTyped.

Before Typescript I imported Express with a "require" statement

var express = require("express")

No I need to import it in way that I can use Typescript Syntax and capabilities while ensuring that the Typescript compiler compiles it to the statement shown above. Here's the code I wrote:

/// <reference path="express.d.ts" />
import express = require("express");
var app = express.express();
app.use(express.logger());

This however throws the error: Unresolved function or method express() at:

var app = express.express();

Upvotes: 0

Views: 2317

Answers (1)

basarat
basarat

Reputation: 275819

I believe that should be :

import express = require('express');
var app = express();

See example : https://github.com/borisyankov/DefinitelyTyped/blob/master/express/express-tests.ts#L3-L4

Upvotes: 5

Related Questions