I have a typescript external module in "main.ts", which only exports a single function, written in this way:
// ...
import O = require('./Options');
"use strict";
function listenRestRoutes(expressApp: any, options?: O.IOptions) {
// ...
}
module.exports = listenRestRoutes;
This one compiles well. And I have another file, where this module is imported:
// ...
import express = require('express');
import mipod = require('./main');
import O = require('./Options');
// ...
var app = express();
var opts: O.IOptions = O.Options.default();
// ...
mipod(app, opts);
The last line doesn't compile, saying error TS2088: Cannot invoke an expression whose type lacks a call signature. mipod(app, opts);
I don't understand why I get this error. Despite this error, the javascript is correctly generated and runs well. So, is it a compiler bug, or is there something bugged in my code?
PS: I also tried to add reference on top of the second file:
/// <reference path="./main.ts" />
But it doesn't change anything.
TypeScript doesn't parse module.exports assignments for type information. Instead of this line:
module.exports = listenRestRoutes;
Use this
export = listenRestRoute;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With