Skip to content

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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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 🙈

@@ -36,7 +36,8 @@ export function typescript(options: ConfigOptions): Linter.Config[] {
],
rules: {
// 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
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