-
-
Notifications
You must be signed in to change notification settings - Fork 616
Open
Labels
Description
Type description + examples
With typescript now supporting predicate inference for guard functions without the need for explicitly specifying a is
clause, it could be interesting to provide a simple helper that allows to get the inferred predicate for any guard function.
Ex.:
function isValid(value: string | number | null | undefined | false) {
return value != null && value !== false;
} // : value is string | number
type Valid = Predicate<typeof isValid> // string | number
Type source
export type Predicate<T> = T extends (x: any) => x is infer U ? U : never;
Search existing types and issues first
- I tried my best to look for it
sindresorhus, fregante and ethanresnick