Skip to content

Explicit keyword for type-only import #20433

Closed
@rokoroku

Description

@rokoroku

I'd like to suggest an explicit keyword for type-only import. e.g.

Suggestion

// moduleA.ts
export class ClassA {
  ...
  static someStaticFn(class: ClassA) { ... }
}

// moduleB.ts
import type { ClassA } from './moduleA';

export function aFunction(classA: ClassA) {
  ClassA.someStaticFn(classA); 
  ~~~~~
  cannot use type-only imports as a real expression!
}

Related:
https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-imports-being-elided-in-my-emit


Purpose

The type-only import (which are elided in the output file) is really useful when writing argument types. However, we sometimes mistakenly use imported variables as the real expression, which sometimes causes circular dependency errors.

If we have an explicit keyword for that kind of imports, it will help reduce the errors.

Is there any feature to achieve this scenario?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions