[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"]
  }
}

 

posted @ 2020-10-09 01:24  Zhentiw  阅读(152)  评论(0编辑  收藏  举报