Open lieberkind opened 1 year ago
The O.filter function doesn't have an overload that takes type guards into account. The only definition that exists looks like this:
O.filter
export declare function filter<A>(predicateFn: (value: A) => boolean): (option: Option<A>) => Option<A>;
Compare this to A.filter which has an overload that allows for a type guard to be passed in:
A.filter
export declare function filter<A, B extends A>(predicateFn: (value: A) => value is B): (xs: Array<A>) => Array<B>;
It would be nice to have the same for O.filter.
Here's an example that currently fails:
type WithOrWithoutYou = {type: 'with', you: string} | {type: 'without'}; declare const withOrWithout: WithOrWithoutYou; pipe( O.some(withOrWithout), O.filter(w => w.type === 'with'), O.map(w => w.you), // <--- Fails with: Property 'you' does not exist on type 'WithOrWithoutYou'. )
Thanks for a great library! 🙌
Hi. I made a PR to resolve this issue. please have a look and let me know if it's right.
The
O.filter
function doesn't have an overload that takes type guards into account. The only definition that exists looks like this:Compare this to
A.filter
which has an overload that allows for a type guard to be passed in:It would be nice to have the same for
O.filter
.Here's an example that currently fails:
Thanks for a great library! 🙌