[Typescript] Emitting Declaration Files

Sometime when you create a library, you want types create automatcially for you, instead of typing all the types information by yourself.

// tsconfig.josn

{
  "compilerOptions": {
    "declaration": true,
    "target": "es5",
    "module": "commonjs",
    "lib": ["dom", "es6"],
    "outDir": "dist",
    "typeRoots": ["src/@types", "node_modules/@types"]
  }
}

It will generate types file inside dist folder.

If you want to change the location of types files, you can do:

{
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "./@types",
    "target": "es5",
    "module": "commonjs",
    "lib": ["dom", "es6"],
    "outDir": "dist",
    "typeRoots": ["src/@types", "node_modules/@types"]
  }
}
原文地址:https://www.cnblogs.com/Answer1215/p/13783475.html