Skip to content

Comments

fix(typescript): allow import in type annotation#1034

Merged
susnux merged 1 commit intomainfrom
fix/consistent-type-imports-in-annotations
May 26, 2025
Merged

fix(typescript): allow import in type annotation#1034
susnux merged 1 commit intomainfrom
fix/consistent-type-imports-in-annotations

Conversation

@ShGKme
Copy link
Contributor

@ShGKme ShGKme commented May 13, 2025

Resolves

By default @typescript-eslint/consistent-type-imports forbids dynamic import for type annotations like:

declare interface Window {
	t: typeof import('@nextcloud/l10n').t
	n: typeof import('@nextcloud/l10n').n
}

But for declaration files .d.ts it is important. Otherwise it becomes a module.

@ShGKme ShGKme requested a review from susnux May 13, 2025 18:54
@ShGKme ShGKme self-assigned this May 13, 2025
@ShGKme ShGKme added bug Something isn't working 3. to review labels May 13, 2025
@susnux
Copy link
Contributor

susnux commented May 13, 2025

But I have never seen developers doing it.

I did see this 🙈

// Do not allow to import types with `import` but require `import type`
'@typescript-eslint/consistent-type-imports': 'error',
// Except for type annotations, where dynamic import are often used, for example, in .d.ts files
'@typescript-eslint/consistent-type-imports': ['error', { disallowTypeAnnotations: false }],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO makes sense iff used in d.ts

@ShGKme
Copy link
Contributor Author

ShGKme commented May 13, 2025

But I have never seen developers doing it.

I did see this 🙈

ok :(

@ShGKme ShGKme force-pushed the fix/consistent-type-imports-in-annotations branch from cf51d0b to 340f1e5 Compare May 13, 2025 20:03
@ShGKme ShGKme requested a review from susnux May 13, 2025 20:03
@ShGKme ShGKme force-pushed the fix/consistent-type-imports-in-annotations branch from 340f1e5 to d3c9234 Compare May 13, 2025 20:05
@ShGKme
Copy link
Contributor Author

ShGKme commented May 23, 2025

@susnux What do you think about the current approach?

Copy link
Contributor

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nice!

@susnux susnux merged commit 7d23ead into main May 26, 2025
10 checks passed
@susnux susnux deleted the fix/consistent-type-imports-in-annotations branch May 26, 2025 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants