@wessberg/typescript-package-reassembler
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

TypescriptPackageReassembler

NPM version License-mit

A library that can (re)add type information from a Typescript SourceFile to another. Useful for 'merging' declarations with compiled un-typed files, for example inside node_modules

Installation

Simply do: npm install @wessberg/typescript-package-reassembler.

What is it

A library that can (re)add type information from a Typescript SourceFile to another. Useful for 'merging' declarations with compiled un-typed files. The most probable use case (and the one this was built primarily for) is if you want to parse code from a library inside node_modules and want Typescript's AST to use the type-information from the declaration file (".d.ts") that exists within the same directory.

Usage

// Generate a Typescript AST for the compiled code somehow
const compiledStatements = someTypescriptLanguageService.addFile("/path_to_file.js");
// // Generate a Typescript AST for the declaration file somehow
const declarationStatements = someTypescriptLanguageService.addFile("/path_to_file.d.ts");

const reassembler = new TypescriptPackageReassembler();

// Get the new SourceFile. Content is the new string representation of the file. It will look like the compiled one, except it will include the type information from the declaration statements
const {content, sourceFile} = reassembler.reassemble({compiledStatements, declarationStatements});

Package Sidebar

Install

npm i @wessberg/typescript-package-reassembler

Weekly Downloads

0

Version

0.0.13

License

MIT

Unpacked Size

238 kB

Total Files

87

Last publish

Collaborators

  • wessberg