Skip to content

⬅️ Back to Table of Contents

📄 isTypeImport

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 4

📚 Table of Contents

🛠️ File Location:

📂 packages/eslint-plugin/src/util/isTypeImport.ts

📦 Imports

Name Source
Definition @typescript-eslint/scope-manager
ImportBindingDefinition @typescript-eslint/scope-manager
DefinitionType @typescript-eslint/scope-manager
AST_NODE_TYPES @typescript-eslint/utils

Functions

isTypeImport(definition: Definition): definition is ImportBindingDefinition

Determine whether a variable definition is a type import. e.g.:

import type { Foo } from 'foo';
import { type Bar } from 'bar';

Parameters:

  • definition any: The variable definition to check.
Raw JSDoc
/**
 * Determine whether a variable definition is a type import. e.g.:
 *
 * ```ts
 * import type { Foo } from 'foo';
 * import { type Bar } from 'bar';
 * ```
 *
 * @param definition - The variable definition to check.
 */
Code
export function isTypeImport(
  definition?: Definition,
): definition is ImportBindingDefinition {
  return (
    definition?.type === DefinitionType.ImportBinding &&
    (definition.parent.importKind === 'type' ||
      (definition.node.type === AST_NODE_TYPES.ImportSpecifier &&
        definition.node.importKind === 'type'))
  );
}

Generated by Syntax Scribe