typescript.d.ts

How can I write TypeScript definition files that depend on another definition file?


I'm writing a TypeScript definition file for an existing node library which use building node module like http and events.EventEmitter as a parameter.

my question is how can I write a definition file for this library? I have tried to copy these modules from node.d.ts into my own definition file, but I don't think this is a good idea.


Solution

  • Your module should include it's own node.d.ts file among your .d.ts file (let's call it my_awesome_lib.d.ts)

    In your .d.ts file you may include the necessary types as following:

    declare module 'my_awesome_lib' {
      import * as express from 'express'; // just as example
      import { EventEmitter } from 'events'; // here you go
      export function foo(EventEmitter e): boolean; // your function
    }