JSPM

@wessberg/typescript-package-reassembler

0.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q47373F
  • 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

Package Exports

  • @wessberg/typescript-package-reassembler

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@wessberg/typescript-package-reassembler) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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});