Skip to main content
Module

x/ts_morph/ts_morph.d.ts>ImportDeclaration

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Very Popular
Latest
class ImportDeclaration
extends ImportDeclarationBase<ts.ImportDeclaration>
import { ImportDeclaration } from "https://deno.land/x/ts_morph@22.0.0/ts_morph.d.ts";

Methods

addNamedImport(namedImport: OptionalKind<ImportSpecifierStructure> | string | WriterFunction): ImportSpecifier

Adds a named import.

addNamedImports(namedImports: ReadonlyArray<OptionalKind<ImportSpecifierStructure> | string | WriterFunction> | WriterFunction): ImportSpecifier[]

Adds named imports.

getAttributes(): ImportAttributes | undefined

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

getDefaultImport(): Identifier | undefined

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.

getImportClause(): ImportClause | undefined

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.

getModuleSpecifier(): StringLiteral

Gets the module specifier.

getModuleSpecifierSourceFile(): SourceFile | undefined

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.

getNamedImports(): ImportSpecifier[]

Gets the named imports.

getNamespaceImport(): Identifier | undefined

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>>
getStructure(): ImportDeclarationStructure

Gets the structure equivalent to this node.

insertNamedImport(index: number, namedImport: OptionalKind<ImportSpecifierStructure> | string | WriterFunction): ImportSpecifier

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.