# Type Alias TargetTypeFromPath<T, P>

TargetTypeFromPath<T, P>: P extends keyof T
? T
: P extends `[].${infer ItemPath}`
? [T] extends [ObservableCollectionLike<infer ItemType>]
? ItemType extends Observable
? ItemPath extends keyof ItemType
? ItemType
: TargetTypeFromPath<ItemType, ItemPath>
: unknown
: unknown
: P extends `${infer K}.${infer Rest}`
? K extends keyof T
? [T[K]] extends [Observable | undefined | null]
? Rest extends `[].${string}`
? TargetTypeFromPath<NonNullable<T[K]>, Rest>
: TargetTypeFromPath<NonNullable<T[K]>, Rest> | (undefined extends T[K]
? undefined
: never)
: unknown
: unknown
: T

The type of the target at the second to last position of a path created from ObservablePropertyPath or CollectionPropertyPath. Only intended for use with ObservablePropertyPath or CollectionPropertyPath.

Because the path was built with ObservablePropertyPath or CollectionPropertyPath, we know that the path is valid. We still have to build out the conditionals for the type system to understand what we are doing, but we don't need to handle the false cases.

This type uses recursion without any depth limits because the path is guaranteed to be valid and of a limited depth.

Note: This is a complex recursive type that should only be used for function definitions related to the observable watch system. It is not intended to be used for general purposes and should not be used by casts or other type manipulations.

#### Type Parameters

- T extends Observable
- P extends string