Generate declaration file programmatically

974 Views Asked by At

I know I can run tsc --declaration myfile.ts to generate a declaration file. Is there some way I can do this programmatically with the TS compiler?

i.e something like

const ts = require('typescript');
const out = ts.declarations('source-string');
1

There are 1 best solutions below

0
On

I think that this github project, can be solution for you: https://github.com/SitePen/dts-generator

Start: npm install dts-generator

Generate your d.ts bundle programmatically:

require('dts-generator').default({
    name: 'package-name',
    project: '/path/to/package-directory',
    out: 'package-name.d.ts'
});

For more info you should visit link above :).