The type to be recursively analyzed.
The condition type that sub-types of T must extend
to be included in the resulting union. Must extend Record<string, any>.
// Define a specific condition type
type SpecificCondition = { specialKey: string }
// Example object type to analyze
type Example = {
a: number
b: { specialKey: string; otherKey: number }
c: { nested: { specialKey: string }; other: number }
d: string[]
}
// Using `MatchObjectDeep`, the result will be a union of `b` and `nested` from `c`,
// as they are the only sub-types that match `SpecificCondition`.
type Result = MatchObjectDeep<Example, SpecificCondition>
type ResultType =
| {
specialKey: string
otherKey: number
}
| {
specialKey: string
}
The type excludes non-recursable types specified in NativeObject, like Date, RegExp, etc., to prevent irrelevant type inclusions.
Generated using TypeDoc
Recursively traverses a type
T, returning a union of all sub-types that match a specified condition,TCondition.TConditionis a constraint that extendsRecord<string, any>. The type checks each sub-type ofTagainst this constraint. If a sub-type extendsTCondition, it is included in the resulting union. The type also traverses arrays and objects (except those specified inNativeObject) to check their elements or properties.