Tarion
Tarion

Reputation: 17134

How to define a Module that is a function in Typescript

I'm looking for a way to write a valid definition file for debug

In JS you call:

var debug = require('debug')('http')

Then you use it like:

debug('my debug message');

I have no clue how to define my debug.d.ts to support that pattern. Any help is wellcome.

Thanks

Upvotes: 1

Views: 61

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 220974

For use in TypeScript you'll have to separate out the call into two parts like so:

import debugMod = require('debug');
var debug = debugMod('http');

The definition file (debug.d.ts) would look like this:

declare module "debug" {
    function dbg(s:string):(s:string) => void;

    export = dbg;
}

Upvotes: 2

Related Questions