Skip to content

Support a user preference for preferring the type keyword in auto-imports #54664

Closed
@schontz

Description

@schontz

Suggestion

Add support in the TS server to include import type and inline type imports when auto-importing.

// TS server auto-imports like so:
import { Foo } from './foo';

// But I want to be able to specify that it should treat types like so:
import type { Foo } from './foo';
// or
import { type Foo } from './foo';

🔍 Search Terms

  • inline type import
  • import type isolatedmodules

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

See above

📃 Motivating Example

Many build systems require isolated modules (e.g., esbuild), and often require that types be thusly marked when imported. According to my understanding, that is only done manually, as enabling isolatedModules doesn't seem to affect things.

💻 Use Cases

Work better with isolated module build system requirements. One could also argue that legibility is improved with type imports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureDomain: Auto-importSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions