How to create a @types/<my-package-name> definition

Steps:

  1. Fork github.com/DefinitelyTyped/DefinitelyTyped

  2. Clone/Pull github.com/<you>/DefinitelyTyped

  3. Within the cloned DefinitelyTyped repo, run: npx dts-gen --dt --name <my-package-name> --template module. This will generate the skeleton for the types.

  4. Do the actual coding of the types within index.d.ts

  5. 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 a package.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
  6. To test your types, you run npm test <my-package-name>

  7. 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>

  8. Once the tests pass, git push origin master

  9. 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
  10. Add a title like [<my-package-name>] Add Definition, some description and let the CI do the magic.

  11. 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