27

I need to write a server in TypeScript and Node.

  1. I downloaded Node from DefinitelyTyped repository
  2. I created my typescript file
  3. Imported the definition
  4. Tries to use it

The result is:

/// <reference path="definitions/commonjs.d.ts" />
/// <reference path="definitions/node.d.ts" />

var http = require("http");

namespace MyProj {
    export class Server {
        public run() {
            var server = http.createServer(); // TypeScript does not recognize 'http'
        }
    }
}

But I cannot understand how I can reference the http module. Where can I find the types? In the definition file i am having hard time recognizing this information.

1 Answer 1

61

It's because of you are using require. use import instead it will recognize and also will give you nice intellisense :-)

import * as http from "http"
Sign up to request clarification or add additional context in comments.

Comments

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.