# Publishing Type Definitions

It can be useful to be able to publish these types in custom NPM repos e.g.[ Gitlab](https://wiki.jamesravey.me/books/node-and-typescript/page/npm-and-gitlab "NPM and Gitlab")

### Configuring `package.json` File

#### Including `src` and `dist` folders

use `files` key in` package.json `to indicate which directories should be published ([https://stackoverflow.com/questions/67523877/index-d-ts-file-not-published-to-npm](https://stackoverflow.com/questions/67523877/index-d-ts-file-not-published-to-npm)). By default you likely want to publish both the source code in `src` and the compiled/transpiled typescript-&gt;js files in `dist`

e.g.

```json
{
  "files": [
    "dist",
    "src"
  ],
}
```

#### Including types and main

#### You also need to include a `types` property which tells npm where your defined types (`index.d.ts`) sits - this is likely to be in `dist/index.d.ts` if you follow the conventions in this document.

#### Main module

In a node module you'd probably use `src/index.js` but we want to use `dist/index.js` - this will be the compiled version of our typescript module.

### Configuring `tsconfig.json`

You probably want something like this:

```json
{
  "compilerOptions": {
      "sourceMap": true,
      "outDir": "dist",
      "strict": true,
      "lib": [
          "esnext"
      ],
      "allowJs": true,
      "declaration": true,
      "esModuleInterop": true
  },
  
  "include": ["src/**/*"],
}
```

Use dist for our `outdir` so that the output from transpilation goes to the right place. Use `declaration: true` to have tsc produce an `index.d.ts`declaration file and plonk it into the `dist` folder so that it is picked up by the package.json we configured above.