ts-morph-structures

Home > ts-morph-structures > ImportManager

ImportManager class

This manages import declarations and specifiers, for including in a source file.

Signature:

export default class ImportManager 

Example

importsManager.addImports({
  pathToImportedModule: "ts-morph",
  isPackageImport: true,
  importNames: ["Structure", "StructureKind"],
  isDefaultImport: false,
  isTypeOnly: true
});
// ...
sourceFile.statements.unshift(...importsManager.getDeclarations());

Constructors

Constructor Modifiers Description
(constructor)(absolutePathToModule)   Constructs a new instance of the ImportManager class

Properties

Property Modifiers Type Description
absolutePathToModule readonly string Where the file will live on the file system.

Methods

Method Modifiers Description
addImports(context)    
getDeclarations()   Get the import declarations, sorted by path to file, then internally by specified import values.