Skip to content

Commit

Permalink
[Fix] no-unresolved: ignore type-only imports
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Sep 17, 2021
1 parent 9c65b9c commit 983a774
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config/typescript.js
Expand Up @@ -2,7 +2,10 @@
* Adds `.jsx`, `.ts` and `.tsx` as an extension, and enables JSX/TSX parsing.
*/

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

module.exports = {

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

// TypeScript compilation already ensures that named imports exist in the referenced module
'import/named': 'off',
'import/no-unresolved': 'off',
},
};
5 changes: 5 additions & 0 deletions src/rules/no-unresolved.js
Expand Up @@ -27,6 +27,11 @@ module.exports = {
const options = context.options[0] || {};

function checkSourceValue(source) {
// ignore type-only imports
if (source.parent && source.parent.importKind === 'type') {
return;
}

const caseSensitive = !CASE_SENSITIVE_FS && options.caseSensitive !== false;
const caseSensitiveStrict = !CASE_SENSITIVE_FS && options.caseSensitiveStrict;

Expand Down

0 comments on commit 983a774

Please sign in to comment.