Skip to content

Commit 67ce20f

Browse files
committed
feat: add rule to forbid inline type imports in TypeScript
- Introduced a new rule that prohibits the use of inline imports in type annotations. - Updated documentation to provide clear examples of correct and incorrect usage. - Emphasized the importance of exporting types separately and importing them at the top of the file for better code clarity and maintainability.
1 parent e76c536 commit 67ce20f

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
description: Forbid inline imports in types - always export and import types separately
3+
globs: **/*.{ts,tsx}
4+
alwaysApply: true
5+
---
6+
7+
# No Inline Type Imports
8+
9+
Never use inline `import()` in type annotations. Always export types from their source module and import them separately.
10+
11+
## ❌ Bad
12+
13+
```typescript
14+
// Inline import in type annotation
15+
benchmarkResults?: import("#/features/codeRunner/lib/workers/codeExec.worker").CodeBenchmarkResponse;
16+
17+
// Inline import in generic
18+
const x: Promise<import("./types").MyType> = fetch();
19+
```
20+
21+
## ✅ Good
22+
23+
```typescript
24+
// Import type at top of file
25+
import type { CodeBenchmarkResponse } from "#/features/codeRunner/lib/workers/codeExec.worker";
26+
27+
// Use imported type
28+
benchmarkResults?: CodeBenchmarkResponse;
29+
```
30+
31+
## Rule
32+
33+
1. Export types from the module where they are defined
34+
2. Use `import type { TypeName } from "module"` at the top of the file
35+
3. Reference the imported type name in annotations

0 commit comments

Comments
 (0)