Skip to content

LeafPaths

Since 1.1.0

Get paths to leaf nodes only (primitive values).

Signature

typescript
type LeafPaths<T, D extends number = 10> = ...

Parameters

ParameterDescription
TThe object type
DMaximum depth (default: 10)

Description

Returns paths only to primitive/leaf values, excluding intermediate object paths.

Examples

Basic Usage

typescript
import type { LeafPaths } from 'uni-types'

interface Data {
  config: {
    host: string
    port: number
    nested: {
      value: boolean
    }
  }
}

type Paths = LeafPaths<Data>
// 'config.host' | 'config.port' | 'config.nested.value'

With Arrays

typescript
interface Users {
  users: { name: string; age: number }[]
}

type Paths = LeafPaths<Users>
// `users.${number}.name` | `users.${number}.age`

Released under the MIT License.