First check if the original package is maintained and open to adding types. Check if the package is being actively maintained; if so, create an issue (or look for existing/closed issues) asking for types to be added, and if the maintainers would be open to merging a PR for it.
If the original package can't have the types, they should be added to Definitely Typed. Check in the DT issues/PRs if anyone else is already working on this.
If no one else is working on it, we're good to create a PR adding them:
- Fork the DT repo. (For Banno, we already have a fork at https://github.com/banno/DefinitelyTyped that can be cloned.)
- Create a new branch for your changes.
- Generate the project:
npx dts-gen --dt --template module --name package-name
wherepackage-name
is the name of the npm package you're adding types for. - Generate the code:
npm i package-name -g; npx dts-gen -m package-name
. This doesn't usually work very well, but it's a start sometimes. - Look through the origina pacakage's docs and/or code and write the types.
- Test the project with
tsc --project types/package-name/tsconfig.json
. - Lint the project with
npm run lint package-name
. - When done, copy it to a project (under
node_modules/@types/package-name
that uses the package and check that it works as expected. - When ready, create a PR in the Definitely Typed repo.
- https://github.com/DefinitelyTyped/DefinitelyTyped#faq
- https://github.com/DefinitelyTyped/DefinitelyTyped#common-mistakes
- http://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html, specifically Do's and Don'ts
- To assert that an expression is of a given type, use $ExpectType (https://github.com/DefinitelyTyped/DefinitelyTyped#lint) (Note: This hasn't really worked for me.)
- http://definitelytyped.org/guides/pull-request.html