Skip to content

no-widen-functions feature request #236

Open
@jleider

Description

@jleider

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions