To generate it programmatically you will need to:
- Setup a
ts.Program based on a tsconfig.json file.
- Emit the program by calling
Program#emit with emitOnlyDtsFiles set to true and provide a custom writeFile callback to capture the output in memory.
Here's an example using @ts-morph/bootstrap because I have no idea how to easily setup a program with a tsconfig.json file using only the TypeScript Compiler API (it takes a lot of code from my understanding and this is easier):
// or import as "@ts-morph/bootstrap" if you're using node/npm
import {
createProjectSync,
ts,
} from "https://deno.land/x/[email protected]/bootstrap/mod.ts";
const project = createProjectSync({
tsConfigFilePath: "tsconfig.json",
});
const files = new Map<string, string>();
const program = project.createProgram();
program.emit(
undefined,
(fileName, data, writeByteOrderMark) => {
if (writeByteOrderMark) {
data = "\uFEFF" + data;
}
files.set(fileName, data);
},
undefined,
/* emitOnlyDtsFiles */ true,
// custom transformers could go here in this argument
);
// use files here