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

no-widen-functions feature request #236

Open
jleider opened this issue Jan 24, 2022 · 0 comments
Open

no-widen-functions feature request #236

jleider opened this issue Jan 24, 2022 · 0 comments

Comments

@jleider
Copy link

jleider commented Jan 24, 2022

While a widen function can be useful for times where the return value isnt cared about, there are ways to avoid needing widen functions at all with a bit of explicit typing. This rule would prevent the use of any W function.

Example bad code:

pipe(
  O.some(1),
  O.foldW( // produces string | number without any sanity checks if thats actually wanted
    () => "foo",
    (v) => v + 1;
  )
);

Example of good code:

pipe(
  O.some(1),
  O.fold(
    (): string | number => "foo", // Typing only needed here due to typescript's left to right type inference
    (v) => v + 1;
  )
);

pipe(
  O.some(1),
  O.fold<number, string | number>( // This option requires the initial type too which is a bit redundant but still satisfies the rule
    () => "foo",
    (v) => v + 1;
  )
);
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

No branches or pull requests

1 participant