The following produces valid, working ES5 but emits the error below. I'm using Typescript 1.7.5 and I think I've read the whole language spec and I cannot figure out why this error is produced.
error TS2349: Cannot invoke an expression whose type lacks a call signature.
a.js (ES5 ambient module with default export)
function myfunc() {
return "hello";
}
module.exports = myfunc;
a.d.ts
declare module "test" {
export default function (): string;
}
b.ts
import test = require("test");
const app = test();
b.js (generated ES5):
var test = require("test");
var app = test()
a
andb
.a
is an ES5 commonjs module with no preexisting type declaration file.b
is typescript consuminga
. Also, therequire()
inb.ts
is changed from"./test"
to"test"
as it should be a string literal for an external ambient module. I'm surprised it worked with"./test"
as the relative path totest.js
, but it worked. But this is better because it's the recommended way from the Typescript spec. – Patrizia