- Rule: typed-rocks/max-depth
- Prevents usage of overly complex or deeply nested TypeScript types.
- Encourages maintainable, readable, and simple type definitions.
- Helps teams enforce a maximum type complexity policy.
// ❌ Too complex:
// ❌ No reusable types:
type Team = {
members: {
name: string;
firstname: string;
address: {
street: {
name: string;
// ^^^ Type is too deeply nested (4). Max allowed is 3
nr: string;
// ^^ Type is too deeply nested (4). Max allowed is 3
};
postalCode: string;
city: string;
};
}[];
};
// ✅ Simpler, more maintainable
// ✅ Reusable
// ✅ No duplication
type Regions = "north" | "south" | "west" | "east";
type Team = {
region: Regions;
members: Member[];
};
type Member = {
name: string;
firstname: string;
address: {
street: {
name: string;
nr: string;
};
postalCode: string;
city: string;
};
};
npm install eslint-plugin-typed-rocks --save-dev
Add typed-rocks
to your ESLint plugins and enable the rule:
{
"plugins": ["typed-rocks"],
"rules": {
"typed-rocks/max-depth": ["warn", 3]
}
}
- Prevents hard-to-read and hard-to-maintain type definitions.
- Encourages best practices in TypeScript codebases.
- Makes code reviews and onboarding easier.
MIT License