You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.:
functionisValid(value: string|number|null|undefined|false){returnvalue!=null&&value!==false;}// : value is string | numbertypeValid=Predicate<typeofisValid>// string | number
Type source
exporttypePredicate<T>=Textends(x: any)=>x is infer U ? U : never;
Search existing types and issues first
I tried my best to look for it
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
The funding will be given to active contributors.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
Sounds useful, but the name is slightly confusing. The type extracts the inferred guard type, but a name like Predicate makes it sound like it's for making predicates. Maybe something like GuardType or ExtractGuard?
I agree Predicate is probably not the best naming, but I don't think derivatives of Guard sound right either since the guard is technically the check, not it's resulting assertion. Maybe GuardedType or just Guarded?
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.:
Type source
Search existing types and issues first
Upvote & Fund
The text was updated successfully, but these errors were encountered: