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" });
});
}