• publishing to the @types organization on npm.If your package is written in TypeScript then the first approach is favored.Use the flag to generate declaration files.This way, your declarations and JavaScript will always be in sync.

    If your package is not written in TypeScript then the second is the preferred approach.

    Including declarations in your npm package

    If your package has a main .js file, you will need to indicate the main declaration file in your package.json file as well.Set the types property to point to your bundled declaration file.For example:

    Note that the "typings" field is synonymous with "types", and could be used as well.

    Also note that if your main declaration file is named index.d.ts and lives at the root of the package (next to index.js) you do not need to mark the "types" property, though it is advisable to do so.

    All dependencies are managed by npm.Make sure all the declaration packages you depend on are marked appropriately in the "dependencies" section in your package.json.For example, imagine we authored a package that used Browserify and TypeScript.

    Here, our package depends on the browserify and packages.browserify does not bundle its declaration files with its npm packages, so we needed to depend on @types/browserify for its declarations.typescript, on the other hand, packages its declaration files, so there was no need for any additional dependencies.

    Red flags

    Don’t use in your declaration files.

    Do use /// <reference types="…" /> instead.

    Make sure to revisit the section for more information.

    Packaging dependent declarations

    • Don’t combine it with yours, keep each in their own file.
    • Do depend on the npm type declaration package if it doesn’t package its declaration files.

    Publish to @types

    Packages under the @types organization are published automatically from using the types-publisher tool.To get your declarations published as an @types package, please submit a pull request to .You can find more details in the contribution guidelines page.