0

I'm trying to specify a function parameter type in a Node app. This is what I came up with:

import express = require("express");

module.exports = (app) => {
    app.get('/', (req: express.Request, res: express.Response) => { // <- this fails to compile
        // do work
    });
}

and it generates this JS, which is not quite right, apparently:

define(["require", "exports"], function(require, exports) {
    module.exports = function (app) {
      //......
    };
});

TS definitions are coming from DefinitelyTyped. "express" is defined as

declare module "express" {

in a .d.ts file.

Obviously i'm doing it wrong.. Any hints?

EDIT: To expand on basarat's answer: In csproj file find TypeScriptModuleKind entry, and set it to COMMONJS.

The ts ended up looking like this:

import express = require("express");

module.exports = (app: express.Application) => {
    app.get("/", (req, res) => {
        res.send({ name: "woohooo" });
    });
}

1 Answer 1

1

The javascript generated looks like :

define(["require", "exports"], function(require, exports) {
    module.exports = function (app) {
      //......
    };
});

because you are compiling with --module amd. For node you should use --module commonjs see : http://www.youtube.com/watch?v=KDrWLMUY0R0&hd=1

PS: you need to reference the express type definitions for TypeScript to know about express usage : https://github.com/borisyankov/DefinitelyTyped/blob/master/express/express-tests.ts#L77 The definition : https://github.com/borisyankov/DefinitelyTyped/blob/master/express/express.d.ts

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.