No Shared Type Import
Enforce type layering by preventing code files from importing shared type files directly. Shared types should only be imported by .d.ts files.
Summary
The no-shared-type-import rule reports imports from shared type files (e.g., shared.d.ts) when the importing file is not a .d.ts file. This enforces a layered type architecture where shared types flow through domain .d.ts files before reaching code files.
Why Use This Rule?
- Enforces a clean type hierarchy:
shared.d.tsto domain.d.tsto.tscode. - Prevents code files from depending on low-level shared types directly.
- Makes refactoring safer because shared type changes only propagate through domain type files.
Examples
- Correct
- Incorrect
// In a .d.ts file — importing shared types is allowed.
// types/cli/runner.d.ts
import type { EntryCategory } from '@/types/shared.d.ts';
export type RunnerRecordSelectedCategory = EntryCategory;
// In a .ts code file — import from the domain .d.ts file.
// cli/runner.ts
import type { RunnerRecordSelectedCategory } from '@/types/cli/runner.d.ts';
// In a .ts code file — importing shared types directly.
// cli/runner.ts
import type { EntryCategory } from '@/types/shared.d.ts';
Configuration
Enable the rule in your ESLint flat config:
import { noSharedTypeImport } from '@cbnventures/nova/rules/eslint';
export default [
{
plugins: {
'@cbnventures/nova': {
rules: {
'no-shared-type-import': noSharedTypeImport,
},
},
},
rules: {
'@cbnventures/nova/no-shared-type-import': ['error', {
sharedFiles: ['shared.d.ts'],
}],
},
},
];
Options
| Option | Type | Default | Description |
|---|---|---|---|
sharedFiles | string[] | [] | File paths or suffixes that identify shared type files (e.g., ['shared.d.ts']). |
Each entry in sharedFiles is matched against the end of the import source path. For example, 'shared.d.ts' matches any import whose source ends with /shared.d.ts.
Troubleshooting
- Error fires on a
.d.tsfile. — The rule skips.d.tsfiles entirely. If the file is a.d.tsbut the error still fires, check that the filename extension is correct. - Want to allow multiple shared files. — Add each shared file path to the
sharedFilesarray (e.g.,['shared.d.ts', 'common.d.ts']).