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/no-ambiguous-success-type.md.
  • English
  • no-ambiguous-success-type

    Disallows non-specific types in the success position of Result, ResultAsync, and ResultMaybeAsync.

    Rule Details

    When the success type of a Result is vague, callers don't know what they receive on success and have to check or cast the value themselves. Use a concrete type instead.

    The following types are reported in the success position: unknown, any, object, and {}. void is allowed for operations that don't return a value.

    The rule checks explicit type annotations such as Result.Result<T, E>. Types inferred by TypeScript are not checked.

    Incorrect

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    class
    class FetchError
    FetchError
    extends
    var Error: ErrorConstructor
    Error
    {}
    // ❌ unknown type
    type FetchResult1 = Result.Success<unknown> | Result.Failure<FetchError>
    FetchResult1
    =
    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
    <unknown,
    class FetchError
    FetchError
    >;
    // ❌ any type
    type FetchResult2 = Result.Failure<FetchError> | Result.Success<any>
    FetchResult2
    =
    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
    <any,
    class FetchError
    FetchError
    >;
    // ❌ object type
    type FetchResult3 = Result.Failure<FetchError> | Result.Success<object>
    FetchResult3
    =
    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
    <object,
    class FetchError
    FetchError
    >;

    Correct

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    class
    class FetchError
    FetchError
    extends
    var Error: ErrorConstructor
    Error
    {}
    // ✅ A concrete type type
    type FetchResult = Result.Success<{
        id: string;
    }> | Result.Failure<FetchError>
    FetchResult
    =
    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
    <{
    id: string
    id
    : string },
    class FetchError
    FetchError
    >;
    // ✅ void for operations that return no value type
    type DeleteResult = Result.Failure<FetchError> | Result.Success<void>
    DeleteResult
    =
    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
    <void,
    class FetchError
    FetchError
    >;
    Tip

    When a value really is unknown, such as a parsed JSON body, validate it with Result.parse to obtain a concrete type.

    Options

    This rule has no options.