eslint-plugin-fp-ts icon indicating copy to clipboard operation
eslint-plugin-fp-ts copied to clipboard

no-widen-functions feature request

Open jleider opened this issue 3 years ago • 0 comments

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;
  )
);

jleider avatar Jan 24 '22 18:01 jleider