Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am working on the library surveyjs

It uses gulp+webpack to build umd bundle.

I want to create the type definition bundle (or may be just multiple d.ts files) for using in typescript projects. I would like to have something like that:

import * as Survey from 'surveyjs';

All contens for Survey.* is described here: https://github.com/dmitrykurmanov/surveyjs/blob/master/src/entries/ko.ts

I have tried to use: github.com/SitePen/dts-generator and github.com/TypeStrong/dts-bundle but whithout success, could somebody please show me the right direction?

like image 527
Dmitry Kurmanov Avatar asked Oct 20 '16 12:10

Dmitry Kurmanov


People also ask

What is D ts file in TypeScript?

d. ts files are declaration files that contain only type information. These files don't produce . js outputs; they are only used for typechecking. We'll learn more about how to write our own declaration files later.


1 Answers

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

like image 101
Aaron Schmid Avatar answered Nov 02 '22 20:11

Aaron Schmid