remeda
Version:
A utility library for JavaScript and Typescript.
11 lines (9 loc) • 343 B
TypeScript
/**
* Extracts a type predicate from a type guard function for the first argument.
*
* @example
* type TypeGuardFn = (x: unknown) => x is string;
* type Result = GuardType<TypeGuardFn>; // `string`
*/
type GuardType<T, Fallback = never> = T extends (x: any, ...rest: any) => x is infer U ? U : Fallback;
export type { GuardType as G };