TypeScript Utility Types Usage
Detects custom mapped types that duplicate built-in utility types, and reports utility-type leverage.
TypeScript ships with a rich set of utility types (Partial, Pick, Omit, Record, Readonly, Required, and others) that compose to express common type transformations. Custom mapped types that replicate these built-ins (e.g., a hand-written type Optional<T> = { [K in keyof T]?: T[K] }) add maintenance cost without adding capability. This analysis surfaces duplicates and reports overall utility-type usage as a signal of type-system leverage.
A duplicate is decided on the syntax tree and must be exact: the same key set, a value that is exactly T[K], no as clause, and the same modifiers. Mutable<T> (-readonly) is the opposite of Readonly, DeepPartial<T> recurses, and a mapped type whose value depends on the key is not a Record; none of them is reported. The score is 100 minus 20 per duplicate: using built-in utilities never costs points and never offsets a duplicate.
Severity guide
- info
- Utility-type usage is healthy or absent without need for concern.
- warning
- A custom mapped type duplicates a built-in utility type; replace with the built-in.
- critical
- Not currently emitted by this analysis.
Remediation
Replace hand-written mapped types with built-in equivalents (Partial, Pick, Omit, Record, etc.).
Replace hand-written mapped types with built-in equivalents (Partial, Pick, Omit, Record, etc.).