Reputation: 3042
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.
Upvotes: 6
Views: 1936
Reputation: 10243
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
}
Upvotes: 7
Reputation: 10489
Use the Typings tool with a typings.json
file to manage TypeScript definition dependencies.
See that project's FAQ
Start by creating a new
typings.json
file, then add dependencies as normal. When you publish to GitHub, locally, alongside your package (NPM or Bower) or even to your own website, someone else can reference it and use it.{ "name": "typings", "main": "path/to/definition.d.ts", "author": "Blake Embrey <[email protected]>", "description": "The TypeScript definition dependency manager", "dependencies": {} }
- main The entry point to the definition (canonical to "main" in NPM's package.json)
- browser A string or map of paths to override when resolving (following the browser field specification)
- ambient Denote that this definition must be installed as ambient
- name The name of this definition
- postmessage A message to emit to users after installation
- version The semver range this definition is typed for
- dependencies A map of dependencies that need installing
- devDependencies A map of development dependencies that need installing
- ambientDependencies A map of environment dependencies that may need installing
- ambientDevDependencies A map of environment dev dependencies that may need installing
Upvotes: 2