How to write a typescript definition file for a node module that exports a function?
Use export =
.
Definition:
declare module 'glob' {
function globs(paths: string, options: any, callback: (err: any, files: string[]) => void): any;
export = globs;
}
Usage (with esModuleInterop enabled):
import glob from 'glob';
glob("*.js", {}, (err, files) => { });
Basarat's answer doesn't work with typescript 2.1.5. You need to declare function and export with export =
:
export = MyFunction;
declare function MyFunction(): string;
How to write a definition file for commonjs module that exports function