Steps:
-
Fork
github.com/DefinitelyTyped/DefinitelyTyped
-
Clone/Pull
github.com/<you>/DefinitelyTyped
-
Within the cloned
DefinitelyTyped
repo, run:npx dts-gen --dt --name <my-package-name> --template module
. This will generate the skeleton for the types. -
Do the actual coding of the types within
index.d.ts
-
If you are using an npmjs package that has built in types (i.e. but not in @types), you will have this error when you try to import some of its types:
Cannot find module 'date-fns' or its corresponding type declarations.ts(2307)
. To solve this, you can add apackage.json
:-
to your package types dir,
DefinitelyTyped/types/<my-package/name>/package.json
:{ "private": true, "dependencies": { "date-fns": "^2.16.1" } }
- Now install your package's dependency(ies) to be able to use its ts declarations with
npm install --prefix /Users/g/Documents/workspace/DefinitelyTyped/types/<my-package-name>
- The error should be gone
- Now install your package's dependency(ies) to be able to use its ts declarations with
-
-
To test your types, you run
npm test <my-package-name>
-
You can also test your types within an existing project that uses your types by copying the contents of what you did above to
<some-project>/node_modules/@types/<my-package-name>
-
Once the tests pass,
git push origin master
-
Create a pull request in github, go to
https://github.com/DefinitelyTyped/DefinitelyTyped/pull
- Inside the Pull requests tab, presse
New Pull Request
- Make sure to click the link
compare across forks
- Now select on the right side your fork
- Inside the Pull requests tab, presse
-
Add a title like
[<my-package-name>] Add Definition
, some description and let the CI do the magic. -
If some of the tests fail, you can keep changing/pushing your local repository, the bot will re-run the tests for you on the same Pull request