ReviseAlgo Logo

Type System Deep Dive

Recursive Types

Master Recursive Type definitions in TypeScript, nested tree structures, JSON data types, deep immutability, and recursive utility types.

Last Updated: July 29, 2026 10 min read

A Recursive Type is a type definition that references itself in its own structure. Recursive types are essential for modeling hierarchical or self-referential data structures such as JSON trees, file directories, linked lists, and expression ASTs.

1. Modeling Tree & Nested Data Structures

2. Typing Arbitrary JSON Data (JSONValue)

One of the classic recursive type definitions is a strictly-typed JSON Value parser:

3. Recursive Utility Types (DeepReadonly)

Recursive types can also be used in mapped types to create Deep Readonly or Deep Partial modifiers that traverse all nested properties:

4. Interactive Code Playground

Test recursive type structures below:

5. Summary Table

Use CaseRecursive Pattern Example
Trees & Graphsinterface Node { children?: Node[]; }
JSON Payloadtype JSONValue = primitive \{ [k: string]: JSONValue } \JSONValue[]
| Deep Mapped Type | type DeepReadonly = { readonly [K in keyof T]: DeepReadonly } |