How to create TypeScript definition file (d.ts) for umd library How to create TypeScript definition file (d.ts) for umd library typescript typescript

How to create TypeScript definition file (d.ts) for umd library


You can ask tsc to generate the declaration files for your code by adding the declaration flag in tsconfig.json.

In your case it would be:

{  "compilerOptions": {    "target": "es5",    "module": "es2015",    "sourceMap": true,    "noImplicitAny": false,    "jsx": "react",    "declaration": true  },//  "filesGlob": [  //    "typings/index.d.ts"  //  ], // TODO  "include": [    "typings/index.d.ts",    "src/**/*"  ],  "exclude": [    "node_modules",    "**/*.spec.ts"  ]}


As toskv mentioned you can use tsc to generate the .d.ts files. Problem there is that the compiler creates multiple declaration files, one for each of your .ts file. I had the same problem with another projected I worked on. I soved it by creating a small plugin for webpack which merges the .d.ts files generated by tsc.

You can check it out on here: https://www.npmjs.com/package/typescript-declaration-webpack-plugin