@codelaw/rules-ts 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,57 @@
1
+ ---
2
+ id: ts/type-only-imports
3
+ title: "Names used only as types are imported with type"
4
+ languages: [typescript, tsx]
5
+ fix: suggest
6
+ fix_reason: "a type-only import is erased, so code that relied on the module's side effects changes"
7
+ stability: preview
8
+ since: 0.1.0
9
+ ---
10
+
11
+ An imported name that the file uses only in type positions is marked `type`.
12
+
13
+ **Why:** Type-only imports are erased at compile time, which keeps runtime imports honest and helps
14
+ bundlers drop unused modules.
15
+
16
+ ```codelaw
17
+ native: ts/type-only-imports
18
+ ```
19
+
20
+ ## Examples
21
+
22
+ ### TypeScript
23
+
24
+ #### Don't
25
+
26
+ ```ts
27
+ import { Config, load } from "./config";
28
+ export const c: Config = load();
29
+ ```
30
+
31
+ #### Do
32
+
33
+ ```ts
34
+ import { type Config, load } from "./config";
35
+ export const c: Config = load();
36
+ ```
37
+
38
+ ### TSX
39
+
40
+ #### Don't
41
+
42
+ ```tsx
43
+ import { Config, load } from "./config";
44
+ export const c: Config = load();
45
+ ```
46
+
47
+ #### Do
48
+
49
+ ```tsx
50
+ import { type Config, load } from "./config";
51
+ export const c: Config = load();
52
+ ```
53
+
54
+ ## Differences from the source
55
+
56
+ Only within the file, without type information: a name used as a value anywhere is left alone.
57
+ Default and namespace imports are reported without a fix.