@razmans/types-checker
v1.0.12
Published
A CLI to detect duplicate TypeScript interfaces in a project
Maintainers
Readme
Types Checker
A TypeScript CLI tool that detects duplicate interfaces across your codebase by analyzing their structure rather than just their names. This helps identify interfaces that have identical properties but different names, which could be candidates for consolidation.
Features
- 🔍 Smart Detection: Finds interfaces with identical property structures, regardless of their names
- 📁 Recursive Scanning: Analyzes single files or entire directories recursively
- 🎯 Property-Based Comparison: Compares interfaces by their actual properties and types, not just names
- 💡 Merge Suggestions: Provides suggested interface definitions for consolidation
- ⚡ Fast Analysis: Built with
ts-morphfor efficient TypeScript AST parsing
Installation
npm install -g @razmans/types-checker
Usage
Command Line Interface
# Analyze a single file
npx @razmans/types-checker ./src/types.ts
# Analyze an entire directory
npx @razmans/types-checker ./srcExample Output
When duplicates are found:
Duplicate interfaces found:
- User (./test/detected/file1.ts)
- Customer (./test/detected/file2.ts)
Suggested merge:
interface User {
id: string;
name: string;
email: string;
}When no duplicates are found:
No duplicate interfaces found.How It Works
The tool analyzes TypeScript interfaces by:
- Parsing: Uses
ts-morphto parse TypeScript files and extract interface declarations - Serialization: Converts each interface's properties into a normalized format for comparison
- Comparison: Groups interfaces with identical property structures
- Reporting: Shows which interfaces are duplicates and suggests merged definitions
Example
Consider these two files:
file1.ts
export interface User {
id: string;
name: string;
email: string;
}file2.ts
export interface Customer {
id: string;
name: string;
email: string;
}The tool will detect that User and Customer have identical structures and suggest they could be consolidated.
Development
Project Structure
├── index.ts # CLI entry point
├── functions/
│ ├── helper.ts # Core logic for finding duplicates
│ └── interface.ts # Type definitions
├── test/
│ ├── detected/ # Test cases with duplicates
│ └── not-detected/ # Test cases without duplicates
└── package.jsonTesting
The project includes test cases in the test/ directory:
test/detected/: Contains interfaces that should be flagged as duplicatestest/not-detected/: Contains interfaces that should not be flagged
Dependencies
ts-morph: TypeScript AST manipulationcommander: CLI frameworktypescript: TypeScript compiler
License
ISC
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Use Cases
- Code Cleanup: Identify redundant interface definitions before refactoring
- Code Review: Catch duplicate interfaces during development
- Legacy Codebase Analysis: Find consolidation opportunities in large codebases
- CI/CD Integration: Automate duplicate detection in your build pipeline
Limitations
- Only analyzes TypeScript interface declarations
- Does not handle complex generic types or conditional types
- Property order is normalized, so interfaces with the same properties in different orders are considered duplicates
