For AI agents: the complete documentation index is available at /byethrow/ja/llms.txt, the full documentation bundle is available at /byethrow/ja/llms-full.txt, and this page is available as Markdown at /byethrow/ja/guide/ecosystem/linter/no-negated-type-guards.md.
  • 日本語
  • no-negated-type-guards

    Result.isSuccess() や Result.isFailure() に否定演算子(!)を使うことを禁止します。

    このルールは自動修正に対応しています。修正時には、否定された呼び出しが反対の型ガードに置き換えられます。

    ルールの詳細

    !Result.isSuccess(result) は Result.isFailure(result) と同じ意味ですが、否定形は読むときに一手間余計にかかります。 Result は常に成功か失敗のどちらかなので、否定の代わりに使える型ガードが必ず存在します。

    誤った例

    import { 
    import Result
    Result
    } from '@praha/byethrow';
    declare 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>;
    // ❌ isSuccess を否定している if (!
    import Result
    Result
    .
    function 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 .

    @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
    .
    function 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 .

    @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';
    declare 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>;
    // ✅ 型ガードを直接使っている if (
    import Result
    Result
    .
    function 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 .

    @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
    .
    function 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 .

    @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
    )) {
    // 成功時の処理 }

    オプション

    このルールにオプションはありません。