Skip to content

Commit

Permalink
Update import/extensions rules in typescript config
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierZal committed Sep 4, 2023
1 parent 6b95a02 commit 301d371
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion config/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
// 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 typeScriptExtensions = ['.ts', '.cts', '.mts', '.tsx'];
const typeScriptKeys = ['ts', 'cts', 'mts', 'tsx'];
const typeScriptExtensions = typeScriptKeys.map((key) => `.${key}`);
const typeScriptFiles = typeScriptExtensions.map((ext) => `**/*${ext}`);

const allExtensions = [...typeScriptExtensions, '.js', '.jsx'];

const typeScriptRules = Object.fromEntries(
typeScriptKeys.map((key) => [key, 'never']),
);

module.exports = {
settings: {
'import/extensions': allExtensions,
Expand All @@ -31,4 +37,16 @@ module.exports = {
// TypeScript compilation already ensures that named imports exist in the referenced module
'import/named': 'off',
},
overrides: [
{
files: typeScriptFiles,
rules: {
'import/extensions': [
'error',
'ignorePackages',
typeScriptRules,
],
},
},
],
};

0 comments on commit 301d371

Please sign in to comment.