@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.
- package/LICENSE +23 -0
- package/NOTICE +6 -0
- package/README.md +34 -2
- package/codelaw-pack.toml +6 -0
- package/package.json +14 -4
- package/presets/ts/conventions.toml +4 -0
- package/presets/ts/recommended.toml +23 -0
- package/rules/ts/ban-ts-comment.md +64 -0
- package/rules/ts/no-array-constructor.md +58 -0
- package/rules/ts/no-duplicate-enum-values.md +65 -0
- package/rules/ts/no-empty-object-type.md +65 -0
- package/rules/ts/no-explicit-any.md +61 -0
- package/rules/ts/no-extra-non-null-assertion.md +50 -0
- package/rules/ts/no-misused-new.md +70 -0
- package/rules/ts/no-namespace.md +65 -0
- package/rules/ts/no-non-null-asserted-optional-chain.md +55 -0
- package/rules/ts/no-require-imports.md +54 -0
- package/rules/ts/no-this-alias.md +68 -0
- package/rules/ts/no-unnecessary-type-constraint.md +64 -0
- package/rules/ts/no-unsafe-declaration-merging.md +73 -0
- package/rules/ts/no-unsafe-function-type.md +57 -0
- package/rules/ts/no-unused-expressions.md +61 -0
- package/rules/ts/no-unused-vars.md +68 -0
- package/rules/ts/no-wrapper-object-types.md +49 -0
- package/rules/ts/prefer-as-const.md +47 -0
- package/rules/ts/prefer-namespace-keyword.md +63 -0
- package/rules/ts/triple-slash-reference.md +60 -0
- package/rules/ts/type-only-imports.md +57 -0
|
@@ -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.
|