1 | # `no-restricted-imports`
|
2 |
|
3 | Disallow specified modules when loaded by `import`.
|
4 |
|
5 | ## Rule Details
|
6 |
|
7 | This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) rule.
|
8 |
|
9 | ## How to Use
|
10 |
|
11 | ```jsonc
|
12 | {
|
13 | // note you must disable the base rule as it can report incorrect errors
|
14 | "no-restricted-imports": "off",
|
15 | "@typescript-eslint/no-restricted-imports": ["error"]
|
16 | }
|
17 | ```
|
18 |
|
19 | ## Options
|
20 |
|
21 | See [`eslint/no-restricted-imports` options](https://eslint.org/docs/rules/no-restricted-imports#options).
|
22 | This rule adds the following options:
|
23 |
|
24 | ### `allowTypeImports`
|
25 |
|
26 | (default: `false`)
|
27 |
|
28 | You can specify this option for a specific path or pattern as follows:
|
29 |
|
30 | ```jsonc
|
31 | "@typescript-eslint/no-restricted-imports": ["error", {
|
32 | "paths": [{
|
33 | "name": "import-foo",
|
34 | "message": "Please use import-bar instead.",
|
35 | "allowTypeImports": true
|
36 | }, {
|
37 | "name": "import-baz",
|
38 | "message": "Please use import-quux instead.",
|
39 | "allowTypeImports": true
|
40 | }]
|
41 | }]
|
42 | ```
|
43 |
|
44 | When set to `true`, the rule will allow [Type-Only Imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export).
|
45 |
|
46 | Examples of code with the above config:
|
47 |
|
48 |
|
49 |
|
50 | #### ❌ Incorrect
|
51 |
|
52 | ```ts
|
53 | import foo from 'import-foo';
|
54 | export { Foo } from 'import-foo';
|
55 |
|
56 | import baz from 'import-baz';
|
57 | export { Baz } from 'import-baz';
|
58 | ```
|
59 |
|
60 | #### ✅ Correct
|
61 |
|
62 | ```ts
|
63 | import { foo } from 'other-module';
|
64 |
|
65 | import type foo from 'import-foo';
|
66 | export type { Foo } from 'import-foo';
|
67 |
|
68 | import type baz from 'import-baz';
|
69 | export type { Baz } from 'import-baz';
|
70 | ```
|
71 |
|
72 | ## Attributes
|
73 |
|
74 | - Configs:
|
75 | - [ ] ✅ Recommended
|
76 | - [ ] 🔒 Strict
|
77 | - [ ] 🔧 Fixable
|
78 | - [ ] 💭 Requires type information
|