Module

x/ts_morph/mod.ts>ImportDeclaration

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Very Popular
Go to Latest
class ImportDeclaration
extends ImportDeclarationBase<ts.ImportDeclaration>
import { ImportDeclaration } from "https://dotland.deno.dev/x/ts_morph@21.0.0/mod.ts";

Methods

Adds named imports.

Gets the import attributes or returns undefined if it doesn't exist.

Gets the default import or returns undefined if it doesn't exist.

getDefaultImportOrThrow(message?: string | (() => string)): Identifier

Gets the default import or throws if it doesn't exit.

Gets the import clause or returns undefined if it doesn't exist.

getImportClauseOrThrow(message?: string | (() => string)): ImportClause

Gets the import clause or throws if it doesn't exist.

Gets the module specifier.

Gets the source file referenced in the module specifier or returns undefined if it can't find it.

getModuleSpecifierSourceFileOrThrow(message?: string | (() => string)): SourceFile

Gets the source file referenced in the module specifier or throws if it can't find it.

Gets the module specifier string literal value.

Gets the named imports.

Gets the namespace import identifier, if it exists.

getNamespaceImportOrThrow(message?: string | (() => string)): Identifier

Gets the namespace import if it exists or throws.

getParent(): NodeParentType<ts.ImportDeclaration>
getParentOrThrow(message?: string | (() => string)): NonNullable<NodeParentType<ts.ImportDeclaration>>

Gets the structure equivalent to this node.

Inserts a named import.

insertNamedImports(index: number, namedImports: ReadonlyArray<OptionalKind<ImportSpecifierStructure> | string | WriterFunction> | WriterFunction): ImportSpecifier[]

Inserts named imports into the import declaration.

Gets if the module specifier starts with ./ or ../.

isTypeOnly(): boolean

Gets if this import declaration is type only.

Removes the default import.

Removes all the named imports.

Removes the namespace import.

renameDefaultImport(text: string): this

Renames or sets the provided default import.

set(structure: Partial<ImportDeclarationStructure>): this

Sets the node from a structure.

setAttributes(elements: ReadonlyArray<OptionalKind<ImportAttributeStructure>> | undefined): this

Sets the import attributes.

setDefaultImport(text: string): this

Sets the default import.

setIsTypeOnly(value: boolean): this

Sets if this import declaration is type only.

setModuleSpecifier(text: string): this

Sets the import specifier.

setModuleSpecifier(sourceFile: SourceFile): this

Sets the import specifier.

setNamespaceImport(text: string): this

Sets the namespace import.