For AI agents: the complete documentation index is available at /byethrow/llms.txt, the full documentation bundle is available at /byethrow/llms-full.txt, and this page is available as Markdown at /byethrow/guide/ecosystem/linter/prefer-result-async.md.
  • English
  • prefer-result-async

    Enforces the use of ResultAsync<T, E> instead of Promise<Result<T, E>>.

    This rule is auto-fixable.

    Rule Details

    ResultAsync<T, E> is an alias for Promise<Result<T, E>>. The alias is shorter and makes it immediately clear that a function returns an asynchronous Result.

    Incorrect

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    class
    class UserNotFoundError
    UserNotFoundError
    extends
    var Error: ErrorConstructor
    Error
    {}
    type
    type User = {
        id: string;
        name: string;
    }
    User
    = {
    id: string
    id
    : string;
    name: string
    name
    : string };
    // ❌ Promise<Result<...>> declare const
    const findUser: (id: string) => Promise<Result.Result<User, UserNotFoundError>>
    findUser
    : (
    id: string
    id
    : string) =>
    interface Promise<T>

    Represents the completion of an asynchronous operation

    Promise
    <
    import Result
    Result
    .
    type Result<T, E> = Result.Success<T> | Result.Failure<E>

    A union type representing either a success or a failure.

    @typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@example
    import { Result } from '@praha/byethrow';
    
    const doSomething = (): Result.Result<number, string> => {
      return Math.random() > 0.5
        ? { type: 'Success', value: 10 }
        : { type: 'Failure', error: 'Oops' };
    };
    @categoryCore Types
    Result
    <
    type User = {
        id: string;
        name: string;
    }
    User
    ,
    class UserNotFoundError
    UserNotFoundError
    >>;

    Correct

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    class
    class UserNotFoundError
    UserNotFoundError
    extends
    var Error: ErrorConstructor
    Error
    {}
    type
    type User = {
        id: string;
        name: string;
    }
    User
    = {
    id: string
    id
    : string;
    name: string
    name
    : string };
    // ✅ ResultAsync declare const
    const findUser: (id: string) => Result.ResultAsync<User, UserNotFoundError>
    findUser
    : (
    id: string
    id
    : string) =>
    import Result
    Result
    .
    type ResultAsync<T, E> = Promise<Result.Result<T, E>>

    An asynchronous variant of Result , wrapped in a Promise.

    @typeParamT - The type of the Success value.@typeParamE - The type of the Failure value.@example
    import { Result } from '@praha/byethrow';
    
    const fetchData = async (): Result.ResultAsync<string, Error> => {
      try {
        const data = await fetch('...');
        return { type: 'Success', value: await data.text() };
      } catch (err) {
        return { type: 'Failure', error: err as Error };
      }
    };
    @categoryCore Types
    ResultAsync
    <
    type User = {
        id: string;
        name: string;
    }
    User
    ,
    class UserNotFoundError
    UserNotFoundError
    >;

    Options

    This rule has no options.