0

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();
2
  • Does the definition file not already declare an express namespace? Maybe this is causing a naming clash? Commented Dec 13, 2013 at 8:16
  • The express namespace is there. But doesn't have an express() function inside it. I've added that manually and seems to work for now. Commented Dec 13, 2013 at 14:08

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, You pointed me to "express-tests.ts" and I'm using "express.d.ts". Whats the difference? Which one should I add to my project? I got this working eventually but I had to add the "express()" function manually to express.d.ts file.
You should import express.d.ts. The file express-tests.ts shows you how you can use express.d.ts in your own application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.