Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v5 #780

Open
1 of 12 tasks
ljosberinn opened this issue May 10, 2024 · 1 comment
Open
1 of 12 tasks

v5 #780

ljosberinn opened this issue May 10, 2024 · 1 comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request

Comments

@ljosberinn
Copy link
Owner

ljosberinn commented May 10, 2024

What needs to be done is:

Originally posted by @ljosberinn in #779 (comment)

@ljosberinn ljosberinn added documentation Improvements or additions to documentation enhancement New feature or request dependencies Pull requests that update a dependency file labels May 10, 2024
@ljosberinn ljosberinn mentioned this issue May 10, 2024
9 tasks
@axelboc
Copy link
Contributor

axelboc commented May 10, 2024

Thought I'd share some learnings that may be helpful when you upgrade TypeScript and @typescript-eslint/eslint-plugin (no rush 😉).

TypeScript has deprecated importsNotUsedAsValues since v5. I initially thought the replacement for this was verbatimModuleSyntax but turns out it's a bit more complex because importsNotUsedAsValues was never meant to be used to enforce the import type ... code style in the first place ... and neither is verbatimModuleSyntax.

The recommendation from this article seems to be to remove importsNotUsedAsValues and verbatimModuleSyntax altogether from tsconfig.json and to use ESLint rules instead.

Moreover, with inline type qualifiers, the best practice for dealing with type imports seems to have changed a bit, in particular when it comes to duplicate imports. Here is what I think we should aim for:

  1. Enforce the use of type qualifiers for type-only imports:
    // Correct
    import { type Foo } from './utils'
    const foo: Foo = 1;
    
    // Incorrect
    import { Foo } from './utils'
    const foo: Foo = 1;
  2. Enforce the use of inline type qualifiers for type-only imports (note that statements that contain only inline type imports are correctly removed by tsc when verbatimModuleSyntax is disabled):
    // Correct
    import { type Foo } from './utils'
    
    // Incorrect
    import type { Foo } from './utils'
  3. Never allow duplicate imports, even when types are involved, thanks again to inline type qualifiers:
    // Correct
    import { Bar, type Foo } from './utils'
    
    // Incorrect
    import { Bar } from './utils'
    import type { Foo } from './utils'
    
    // Incorrect
    import { Bar } from './utils'
    import { type Foo } from './utils'

From what I gather, this would be achieved with the following rules:

I think rule import/consistent-type-specifier-style, which is enabled by Galex with { 'prefer-inline': true }, should then be disabled, as I think it does the same thing as { fixStyle: 'inline-type-imports' } in @typescript-eslint/consistent-type-imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants