Type alias SpreadDeepObject<T, TCondition, TValue>

SpreadDeepObject<T, TCondition, TValue>: RecursiveObjectModification<T, TCondition, TValue, "spread">

Recursively generates a type that mimics spreading object T with object TValue, and replaces (plain) objects within a complex object whose shape matches TCondition.

Type Parameters

  • T

    The type to be modified.

  • TCondition extends Record<string, any>

    The condition used to identify objects for spreading.

  • TValue extends Record<string, any>

    The type to spread onto the matching objects.

Example

type DbConfig = {
host: string
port: number
credentials: {
username: string
password: string
}
}

type Config = {
database: DbConfig
service: {
gcRun: {
auth: {
username: string
password: string
key: string
prop1: string
prop2: string
}
}
}
dbConfigs: DbConfig[]
logging: {
level: string
format: "json" | "text"
}
}

type Condition = {
username: string
password: string
}

type NewProperties = {
encrypted: boolean
password: number
}

// Using SpreadDeepObject to spread NewProperties onto parts of Config that match Condition
type UpdatedConfig = SpreadDeepObject<Config, Condition, NewProperties>

// The resulting type would look like this:

type UpdatedConfigResult = {
database: {
host: string
port: number
credentials: {
username: string
password: number // <-- Replaced
encrypted: boolean // <-- New property
}
}
service: {
gcRun: {
auth: {
username: string
password: number // <-- Replaced
key: string
prop1: string
prop2: string
encrypted: boolean // <-- New property
}
}
}
dbConfigs: {
// Also recurses into arrays
host: string
port: number
credentials: {
username: string
password: number // <-- Replaced
encrypted: boolean // <-- New property
}
}[]
logging: {
level: string
format: "json" | "text"
}
}

Returns

The modified type.

Generated using TypeDoc