Skip to content

Improve TypeScript types for effect functions (hopeThat, tryTo, retryTo) #5205

Closed

Description

@danielrentz

The TypeScript types of the effect functions could be improved:

  1. hopeThat

    According to the source code, this function:

    • does not accept an asynchronous callback -- is this intentional?
    • does not use the result of the callback
    • returns a success flag

    Therefore, it can be made non-generic and with a synchronous callback.

    - type HopeThat = <T>(fn: () => Promise<T> | T) => Promise<T | false>;
    + type HopeThat = (fn: () => void) => Promise<boolean>;
  2. tryTo

    According to the source code, this function:

    • does not accept an asynchronous callback -- is this intentional?
    • does not use the result of the callback
    • returns a success flag

    Therefore, it can be made non-generic and with a synchronous callback.

    - type TryTo = <T>(fn: () => Promise<T> | T) => Promise<T | false>;
    + type TryTo = (fn: () => void) => Promise<boolean>;
  3. retryTo

    According to the source code, this function:

    • expects "maxTries" to be defined
    • accepts optional "pollIntervall"
    • passes iteration index to callback
    • does not use the result of the callback
    • returns a success flag

    Therefore, it can be made non-generic with an extended signature.

    - type RetryTo = <T>(fn: () => Promise<T> | T, retries?: number) => Promise<T>;
    + type RetryTo = (fn: (tries: number) => Promise<void> | void, maxTries: number, pollInterval?: number) => Promise<boolean>;

I would open a PR if intended support for asynchronous callbacks in hopeThat and tryTo is clear.

Activity

  1. added a commit that references this issue on Nov 24, 2025
    058ee82
  2. danielrentz commented on Nov 24, 2025

    @danielrentz
    ContributorAuthor

    PR #5335 fixes the type definitions according to the current implementation, i.e. tryTo and hopeThat cannot take an async callback function.

  3. DenysKuchma commented on Feb 11, 2026

    @DenysKuchma
    Collaborator

    You can check the implementation in the beta release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions