@typed-rocks/eslint-plugin-typed-rocks
v1.0.0
Published
A powerful ESLint plugin to enforce and simplify TypeScript type complexity in your codebase.
Readme
eslint-plugin-typed-rocks
A powerful ESLint plugin to enforce and simplify TypeScript type complexity in your codebase.
Features
- Rule: no-complex-types
- Prevents usage of overly complex or deeply nested TypeScript types.
- Encourages maintainable, readable, and simple type definitions.
- Detects and warns about types with excessive nesting, unions, intersections, or computed properties.
- Helps teams enforce a maximum type complexity policy.
Example
// ❌ Too complex:
type Person = {
lastname: string;
firstname: string;
address: {
street: {
name: string;
additional: {
a: string;
[key: string]: string;
};
};
postalCode: string;
city: string;
};
};
// ✅ Simpler, more maintainable:
type Address = {
street: string;
postalCode: string;
city: string;
};
type Person = {
lastname: string;
firstname: string;
address: Address;
};Installation
npm install eslint-plugin-typed-rocks --save-devUsage
Add typed-rocks to your ESLint plugins and enable the rule:
{
"plugins": ["typed-rocks"],
"rules": {
"typed-rocks/no-complex-types": ["warn", {
"union": { "topLevel": 5, "inner": 2 },
"intersection": { "topLevel": 3, "inner": 2 },
"depth": 3,
"unionAndIntersections": { "topLevel": 4, "inner": 2 }
}]
}
}Configuration Options
union,intersection,unionAndIntersections:topLevel: Maximum allowed top-level membersinner: Maximum allowed inner members
depth: Maximum allowed nesting depth for types
Why?
- Prevents hard-to-read and hard-to-maintain type definitions.
- Encourages best practices in TypeScript codebases.
- Makes code reviews and onboarding easier.
MIT License
