spice-island
spice-island

Reputation: 63

Is it possible to have typescript build types and only types to a specific directory?

I'd like to be able to have all of my types across packages built to a specific directory for reuse. I don't want to risk pulling in code from the API to a client package.

Is it possible to have typescript build types and only types to a specific directory?

Upvotes: 6

Views: 5085

Answers (1)

joshwilsonvu
joshwilsonvu

Reputation: 2699

Yes; see the emitDeclarationOnly and declarationDir compiler options. emitDeclarationOnly outputs .d.ts type declaration files only and declarationDir lets you specify a directory to put them, relative to the tsconfig.json file.

{
  "compilerOptions": {
    "emitDeclarationOnly": true,
    "declarationDir": "./types"
  }
}

If you want to build both declarations and compiled .js files, you can replace "emitDeclarationOnly": true with "declaration": true, and the .js files will go to your "outDir" while the .d.ts files will go to your "declarationDir"

Upvotes: 9

Related Questions