Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type guard compatible overload for O.filter #77

Open
lieberkind opened this issue Mar 21, 2023 · 1 comment · May be fixed by #105
Open

Add type guard compatible overload for O.filter #77

lieberkind opened this issue Mar 21, 2023 · 1 comment · May be fixed by #105

Comments

@lieberkind
Copy link

The O.filter function doesn't have an overload that takes type guards into account. The only definition that exists looks like this:

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:

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! 🙌

@JUSTIVE JUSTIVE linked a pull request Feb 11, 2024 that will close this issue
@JUSTIVE
Copy link

JUSTIVE commented Mar 11, 2024

Hi. I made a PR to resolve this issue. please have a look and let me know if it's right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants