从 TypeGuard 提取被守卫的类型
条件类型:若 G 为 TypeGuard<T>,则提取 T;否则为 never。 对联合类型自动分布,得到各分支的联合——这正是 or() 返回类型所需。
G
TypeGuard<T>
T
never
or()
type T = InferGuard<typeof isString>; // stringtype U = InferGuard<typeof isString | typeof isNumber>; // string | number Copy
type T = InferGuard<typeof isString>; // stringtype U = InferGuard<typeof isString | typeof isNumber>; // string | number
从 TypeGuard 提取被守卫的类型
条件类型:若
G为TypeGuard<T>,则提取T;否则为never。 对联合类型自动分布,得到各分支的联合——这正是or()返回类型所需。