Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write d.ts file for JavaScript that exports a default function and a named export

Was attempting to write a d.ts file for worker-farm (https://github.com/rvagg/node-worker-farm) However I ran across an issue.

worker-farm does a module.exports like this:

module.exports     = farm
module.exports.end = end

If I try to do this in typescript such as

export function end(workers:any):void;
export =  workerFarm;

I receive an error saying I can't mix export types. Trying to use default seems to not let me export it either.

Is it possible to replicate this in a definition?

like image 652
Eric Byers Avatar asked Nov 02 '25 07:11

Eric Byers


1 Answers

You can try to use namespaces for this.

Something like:

declare function workerFarm(){}

declare namespace workerFarm
{
    export function end( workers: any ): void;
}

export = workerFarm;

Look at this example in documentation: http://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-function-d-ts.html

like image 82
Avol Avatar answered Nov 04 '25 08:11

Avol