• English
  • Function: isSuccess()

    isSuccess<R>(result): result is Extract<R, { type: "Success" }>

    Type guard to check if a Result is a Success.

    Type Parameters

    R

    R extends Result<unknown, unknown>

    The type of the result to check.

    Parameters

    result

    R

    The Result to check.

    Returns

    result is Extract<R, { type: "Success" }>

    true if the result is a Success, otherwise false.

    Example

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<number, string>
    result
    :
    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
    <number, string> = {
    type: "Success"
    type
    : 'Success',
    value: number
    value
    : 10 };
    if (
    import Result
    Result
    .
    const isSuccess: <Result.Success<number>>(result: Result.Success<number>) => result is Result.Success<number>

    Type guard to check if a Result is a Success .

    @function@typeParamR - The type of the result to check.@paramresult - The Result to check.@returnstrue if the result is a Success , otherwise false.@example
    import { Result } from '@praha/byethrow';
    
    const result: Result.Result<number, string> = { type: 'Success', value: 10 };
    if (Result.isSuccess(result)) {
      console.log(result.value); // Safe access to value
    }
    @categoryType Guards
    isSuccess
    (
    const result: Result.Success<number>
    result
    )) {
    var console: Console
    console
    .
    Console.log(...data: any[]): void

    The console.log() static method outputs a message to the console.

    MDN Reference

    log
    (
    const result: Result.Success<number>
    result
    .
    value: number
    value
    ); // Safe access to value
    }