• 日本語
  • no-negated-type-guards

    Result.isSuccess() または Result.isFailure() に否定演算子(!)を使用することを禁止します。

    ルールの詳細

    !Result.isSuccess(result)Result.isFailure(result) と同等ですが、否定形は可読性が低く、読み手に余分な認知負荷をかけます。このルールは自動修正に対応しています。

    誤り

    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');
    // ❌ 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
    )) {
    // 失敗時の処理 } // ❌ 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
    )) {
    // 成功時の処理 }

    正しい

    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');
    // ✅ 直接の型ガードを使用 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
    )) {
    // 失敗時の処理 } 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
    )) {
    // 成功時の処理 }