Skip to content

Commit 983a774

Browse files
committed
[Fix] no-unresolved: ignore type-only imports
1 parent 9c65b9c commit 983a774

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

config/typescript.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
* Adds `.jsx`, `.ts` and `.tsx` as an extension, and enables JSX/TSX parsing.
33
*/
44

5-
const allExtensions = ['.ts', '.tsx', '.d.ts', '.js', '.jsx'];
5+
// Omit `.d.ts` because 1) TypeScript compilation already confirms that
6+
// types are resolved, and 2) it would mask an unresolved
7+
// `.ts`/`.tsx`/`.js`/`.jsx` implementation.
8+
const allExtensions = ['.ts', '.tsx', '.js', '.jsx'];
69

710
module.exports = {
811

@@ -24,6 +27,5 @@ module.exports = {
2427

2528
// TypeScript compilation already ensures that named imports exist in the referenced module
2629
'import/named': 'off',
27-
'import/no-unresolved': 'off',
2830
},
2931
};

src/rules/no-unresolved.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ module.exports = {
2727
const options = context.options[0] || {};
2828

2929
function checkSourceValue(source) {
30+
// ignore type-only imports
31+
if (source.parent && source.parent.importKind === 'type') {
32+
return;
33+
}
34+
3035
const caseSensitive = !CASE_SENSITIVE_FS && options.caseSensitive !== false;
3136
const caseSensitiveStrict = !CASE_SENSITIVE_FS && options.caseSensitiveStrict;
3237

0 commit comments

Comments
 (0)