Import Optimization
dtsx provides sophisticated import optimization capabilities to ensure your declaration files are clean and efficient.
Smart Import Tracking
dtsx tracks imports in several ways:
- Type imports (
import type
) - Value imports (
import
) - Mixed imports
- Default imports
- Namespace imports
Import Optimization Strategies
Type-Only Imports
typescript
// Before optimization
import { User, UserRole, processUser } from './types';
// After optimization
import type { User, UserRole } from './types';
import { processUser } from './types';
Unused Import Removal
typescript
// Before optimization
import { User, Role, Permission } from './types';
// Only User is used in the file
// After optimization
import { User } from './types';
Import Consolidation
typescript
// Before optimization
import { User } from './types';
import { Role } from './types';
import { Permission } from './types';
// After optimization
import { User, Role, Permission } from './types';
Import Tracking Features
Type Usage Tracking
- Tracks all type references
- Maintains type relationships
- Handles type aliases
- Supports type augmentation
Value Usage Tracking
- Tracks function calls
- Tracks variable usage
- Handles destructuring
- Supports namespace usage
Optimization Rules
- Type-Only Rule: Imports used only as types are converted to type imports
- Unused Removal Rule: Unused imports are removed
- Consolidation Rule: Multiple imports from the same module are consolidated
- Namespace Rule: Namespace imports are optimized based on usage
- Default Import Rule: Default imports are handled appropriately
Configuration Options
typescript
interface ImportOptimizationConfig {
// Enable/disable import optimization
optimizeImports: boolean;
// Keep certain imports even if unused
preserveImports: string[];
// Custom import transformation rules
transformRules: ImportTransformRule[];
}
Best Practices
- Use type imports for type-only usage
- Avoid mixing type and value imports when possible
- Use namespace imports for large modules
- Keep related imports together
- Use consistent import styles