Kind: Type
Source: src/utils/types.ts
Part of: Utils
A simple extension of Simplify that will deeply traverse array elements.
SimplifyDeepArray extends Simplify by recursively processing array element types. It preserves the array structure while simplifying each non-array element type, making nested array types easier to inspect and consume.
Definition
tsT extends any[] ? { [E in keyof T]: SimplifyDeepArray<T[E]> } : Simplify<T>
Diagram
mermaidgraph LR Input[Input type] --> Check{Is an array?} Check -->|Yes| Recurse[Apply SimplifyDeepArray to element type] Recurse --> Array[Return array of simplified elements] Check -->|No| Simplify[Apply Simplify]
Usage
tstype ApiRecord = {
id: string;
metadata: {
createdBy: string;
};
};
type NestedRecords = ApiRecord[][];
type SimplifiedRecords = SimplifyDeepArray<NestedRecords>;
// SimplifiedRecords is:
// Array<Array<{
// id: string;
// metadata: {
// createdBy: string;
// };
// }>>
AI Coding Instructions
- Use
SimplifyDeepArraywhen a type may contain nested arrays whose element types need simplification. - Keep the recursive array check before applying
Simplifyto non-array values. - Do not replace array element recursion with a shallow
Simplify, or nested array elements will remain unsimplified. - Use
SimplifyDeepArrayfor type-level readability only; it does not transform runtime values.
Was this page helpful?