Call signature missing when exporting typescript function "

I have a typescript external module in "main.ts" that only exports one function, written like this:

// ...
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 does not compile, saying error TS2088: Unable to invoke an expression whose type does not have a invocation signature. mipod (app, opts);

I don't understand why I am getting this error. Despite this error, the javascript is generated correctly and works well. So, is this a compiler error, or is there something in my code?

PS: I also tried adding a link on top of the second file:

/// <reference path="./main.ts" />

      

But it does not change anything.

+3


source to share


1 answer


TypeScript does not parse module.exports

assignments for type information. Instead of this line:

module.exports = listenRestRoutes;

      



Use this

export = listenRestRoute;

      

+6


source







All Articles