Equivalent of module.exports in Typescript Declaration file
You need to use the special export =
and import Library = require
syntax, as pointed out by @Nitzan:
export = and import = require()
A complete example:
node_modules/library/index.js
module.exports = function(arg) {
return 'Hello, ' + arg + '.';
}
library.d.ts
This filename technically does not matter, only the .d.ts
extension.
declare module "library" {
export = function(arg: string): string;
}
source.ts
import Library = require('library');
Library('world') == 'Hello, world.';
You must use this syntax in the case of export =
:
import Library = require("library");
More about it here: export = and import = require()