Skip to content

Configuration to auto-import with inline type specifiersΒ #63493

@angrybacon

Description

@angrybacon

πŸ” Search Terms

"inline type specifiers", "preferTypeOnlyAutoImports"

βœ… Viability Checklist

⭐ Suggestion

Preamble

I did check the "Design Goals" guideline from the checklist but have doubts towards this one item since import { type T } from ... and import type { T } from ... don't necessarily behave the same wrt/ bundlers

  1. Use a consistent, fully erasable, structural type system.

For reference, this issue was ported from typescript-language-server/typescript-language-server#1068

This issue is about providing more control over the user preference preferTypeOnlyAutoImports. I suppose instead of a boolean, it could also accept one of the 2 known styles (to my knowledge): top-level and inline. Though the next question becomes: what happens when a user configures inline and another import statement from the same location already exists in the file using the top-level syntax (and vice versa)

βœ… Use Case A

Auto-importing FooProps behaves as expected when a symbol is already imported from the same path

import { Foo, type FooProps } from 'foo';

❌ Use Case B

Current behavior auto-importing FooProps when no symbols are imported from the location yet

import type { FooProps } from 'foo';

Expected behavior

import { type FooProps } from 'foo';

πŸ“ƒ Motivating Example

See https://oxc.rs/docs/guide/usage/linter/rules/import/consistent-type-specifier-style.html

πŸ’» Use Cases

  1. What do you want to use this for?
    Have consistent import styles across the codebase

  2. What shortcomings exist with current approaches?
    Auto-importing uses the wrong style by default when importing from a then unused path which has to be fixed in order to pass the linter

  3. What workarounds are you using in the meantime?
    No workaround

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions