• English
  • no-negated-type-guards

    Disallows using the negation operator (!) on Result.isSuccess() or Result.isFailure().

    Rule details

    !Result.isSuccess(result) is equivalent to Result.isFailure(result), but the negated form is less readable and requires an extra mental step to parse. This rule auto-fixes violations.

    Incorrect

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<string, Error>
    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
    <string, Error> =
    import Result
    Result
    .
    const succeed: <"hello">(value: "hello") => Result.Result<"hello", never> (+1 overload)
    succeed
    ('hello');
    // ❌ negating isSuccess if (!
    import Result
    Result
    .
    const isSuccess: <Result.Result<string, Error>>(result: Result.Result<string, Error>) => result is Result.Success<string>

    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.Result<string, Error>
    result
    )) {
    // handle failure } // ❌ negating isFailure if (!
    import Result
    Result
    .
    const isFailure: <Result.Result<string, Error>>(result: Result.Result<string, Error>) => result is Result.Failure<Error>

    Type guard to check if a Result is a Failure .

    @function@typeParamR - The type of the result to check.@paramresult - The Result to check.@returnstrue if the result is a Failure , otherwise false.@example
    import { Result } from '@praha/byethrow';
    
    const result: Result.Result<number, string> = { type: 'Failure', error: 'Something went wrong' };
    if (Result.isFailure(result)) {
      console.error(result.error); // Safe access to error
    }
    @categoryType Guards
    isFailure
    (
    const result: Result.Result<string, Error>
    result
    )) {
    // handle success }

    Correct

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    const
    const result: Result.Result<string, Error>
    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
    <string, Error> =
    import Result
    Result
    .
    const succeed: <"hello">(value: "hello") => Result.Result<"hello", never> (+1 overload)
    succeed
    ('hello');
    // ✅ using the direct type guard if (
    import Result
    Result
    .
    const isFailure: <Result.Result<string, Error>>(result: Result.Result<string, Error>) => result is Result.Failure<Error>

    Type guard to check if a Result is a Failure .

    @function@typeParamR - The type of the result to check.@paramresult - The Result to check.@returnstrue if the result is a Failure , otherwise false.@example
    import { Result } from '@praha/byethrow';
    
    const result: Result.Result<number, string> = { type: 'Failure', error: 'Something went wrong' };
    if (Result.isFailure(result)) {
      console.error(result.error); // Safe access to error
    }
    @categoryType Guards
    isFailure
    (
    const result: Result.Result<string, Error>
    result
    )) {
    // handle failure } if (
    import Result
    Result
    .
    const isSuccess: <Result.Result<string, Error>>(result: Result.Result<string, Error>) => result is Result.Success<string>

    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.Result<string, Error>
    result
    )) {
    // handle success }