You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/rules/no-duplicate-imports.md
+62-1Lines changed: 62 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,12 @@ import * as something from 'module';
61
61
62
62
## Options
63
63
64
-
This rule takes one optional argument, an object with a single key, `includeExports` which is a `boolean`. It defaults to `false`.
64
+
This rule has an object option:
65
+
66
+
*`"includeExports"`: `true` (default `false`) checks for exports in addition to imports.
67
+
*`"allowSeparateTypeImports"`: `true` (default `false`) allows a type import alongside a value import from the same module in TypeScript files.
68
+
69
+
### includeExports
65
70
66
71
If re-exporting from an imported module, you should add the imports to the `import`-statement, and export that directly, not use `export ... from`.
67
72
@@ -110,3 +115,59 @@ export * from 'module';
110
115
```
111
116
112
117
:::
118
+
119
+
### allowSeparateTypeImports
120
+
121
+
TypeScript allows importing types using `import type`. By default, this rule flags instances of `import type` that have the same specifier as `import`. The `allowSeparateTypeImports` option allows you to override this behavior.
122
+
123
+
Example of **incorrect** TypeScript code for this rule with the default `{ "allowSeparateTypeImports": false }` option:
* @param {Map} modules A Map object contains as a key a module name and as value an array contains objects, each object contains a node and a declaration type.
137
157
* @param {string} declarationType A declaration type can be an import or export.
138
158
* @param {boolean} includeExports Whether or not to check for exports in addition to imports.
159
+
* @param {boolean} allowSeparateTypeImports Whether to allow separate type and value imports.
* @param {Map} modules A Map object contains as a key a module name and as value an array contains objects, each object contains a node and a declaration type.
197
243
* @param {string} declarationType A declaration type can be an import or export.
198
244
* @param {boolean} includeExports Whether or not to check for exports in addition to imports.
245
+
* @param {boolean} allowSeparateTypeImports Whether to allow separate type and value imports.
199
246
* @returns {nodeCallback} A function passed to ESLint to handle the statement.
200
247
*/
201
248
functionhandleImportsExports(
202
249
context,
203
250
modules,
204
251
declarationType,
205
252
includeExports,
253
+
allowSeparateTypeImports,
206
254
){
207
255
returnfunction(node){
208
256
constmodule=getModule(node);
@@ -214,6 +262,7 @@ function handleImportsExports(
214
262
modules,
215
263
declarationType,
216
264
includeExports,
265
+
allowSeparateTypeImports,
217
266
);
218
267
constcurrentNode={ node, declarationType };
219
268
letnodes=[currentNode];
@@ -231,11 +280,14 @@ function handleImportsExports(
0 commit comments