Полезная вещь для дебага, позвоялет "развернуть" сложный тип. Ну то-есть выводит конечный тип после всех дженериков юнионов и тп.
Если совсем просто - вместо
SomeGeneric<SomeOtherGeneric, AnotherGeneric<API["some"]>> получаем структуру из js примитивов/**
* Debugging type that will display a fully resolved type
* in Intellisense instead of just the type aliases
*
* @type {T} The type to expand out
*/
type ExpandRecursively<T> = T extends (...args: infer A) => infer R
? (...args: ExpandRecursively<A>) => ExpandRecursively<R>
: T extends object
? T extends infer O
? { [K in keyof O]: ExpandRecursively<O[K]> }
: never
: T
type Expand<T> = T extends (...args: infer A) => infer R
? (...args: A) => R
: T extends object
? T extends infer O
? { [K in keyof O]: O[K] }
: never
: T
Бонус контент:
чтобы тс вам в ошибках не обрезал тип через ... надо включить
noErrorTruncation в tsconfig