Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 389
Sean Avatar asked Mar 23 '16 15:03

Sean


Video Answer


1 Answers

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
}
like image 176
Manu Avatar answered Sep 22 '22 08:09

Manu