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
export type Predicate<T> = T extends (x: any) => x is infer U ? U : never;
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too