# byethrow > A lightweight, tree-shakable Result type library for type-safe error handling in TypeScript. ## ガイド - [はじめに](/byethrow/ja/guide/start/introduction.md): @praha/byethrowの概要と特徴。Tree Shaking対応、同期・非同期統一処理、pipe関数による型安全なResult型ライブラリの紹介。 - [byethrow を選ぶ理由](/byethrow/ja/guide/start/why.md): neverthrowやeffect-ts・従来のtry/catchと比較しながら、byethrowが実践的な開発に最適な理由と設計思想を説明。 - [クイックスタート](/byethrow/ja/guide/start/quick.md): @praha/byethrowのインストール手順とResult.succeed・Result.fail・Result.pipe・Result.fnを使った基本的な使い方のガイド。 - [Result 型について](/byethrow/ja/guide/tutorial/basics/result-type.md): Result型の構造とSuccess・Failureのユニオン型、例外との違い、ResultAsyncによる同期・非同期の統一処理の仕組みを解説。 - [Result を作成する](/byethrow/ja/guide/tutorial/basics/creating-results.md): Result.succeed・Result.fail・Result.doを使ってSuccessやFailureのResult値を作成する方法と非同期対応の解説。 - [Result を確認する](/byethrow/ja/guide/tutorial/basics/checking-results.md): isSuccess・isFailure・isResultの型ガード関数を使ってResultの状態を安全に判定し、TypeScriptの型を絞り込む方法。 - [関数をラップする](/byethrow/ja/guide/tutorial/basics/wrapping-functions.md): Result.fnとResult.tryを使って例外を投げる可能性のある関数をResult型にラップし、安全に扱う方法の解説。 - [pipe 関数の扱い方](/byethrow/ja/guide/tutorial/chaining/pipe-basics.md): Result.pipe関数を使って複数の操作を左から右へ読みやすく連結する方法と、Resultや非同期処理との組み合わせ方。 - [Result を変換する](/byethrow/ja/guide/tutorial/chaining/mapping-results.md): Result.mapで成功値を変換し、Result.mapErrorでエラー値を変換する方法。ドメインエラーをHTTPレスポンスに変換する実例付き。 - [関数を合成する](/byethrow/ja/guide/tutorial/chaining/chaining-results.md): andThenで成功時の計算を連結しorElseで失敗から回復する、Resultを使った順次処理とエラー回復パターンの解説。 - [検証とエラーからの回復](/byethrow/ja/guide/tutorial/chaining/validation-recovery.md): andThroughで元の値を保持しながらバリデーションを実行し、orThroughで元のエラーを保持しながらクリーンアップ処理を行う方法。 - [Result をデバッグする](/byethrow/ja/guide/tutorial/chaining/debugging.md): Result.inspectとResult.inspectErrorを使ってパイプラインの各ステップで値を副作用なく確認するデバッグ手法。 - [オブジェクトを構築する](/byethrow/ja/guide/tutorial/combining/building-objects.md): Result.doとResult.bindを組み合わせたdo/bindパターンで、複数の依存した計算結果を蓄積しながらオブジェクトを構築する方法。 - [Result を集約する](/byethrow/ja/guide/tutorial/combining/aggregating-results.md): Result.sequenceで最初の失敗で停止し、Result.collectですべてのエラーを収集する複数Resultの集約方法と非同期動作の違い。 - [Result の値を取り出す](/byethrow/ja/guide/tutorial/resolving/unwrapping.md): Result.unwrapで成功値を、Result.unwrapErrorでエラー値を取り出す方法。デフォルト値の指定とアプリケーション境界での適切な使い方。 - [Result を検証する](/byethrow/ja/guide/tutorial/resolving/asserting.md): assertSuccessとassertFailureでコンパイル時にResult型を検証し、unwrapと組み合わせて型安全に値を取り出す方法。 - [Result vs throw](/byethrow/ja/guide/best-practices/result-vs-throw.md): 予期されたビジネスエラーにはResultを、予期しないインフラエラーにはthrowを使い分けるハイブリッドアプローチの解説。 - [Resultのインポート方法](/byethrow/ja/guide/best-practices/importing-result.md): @praha/byethrowのResultとRの2種類のインポート方法、Tree-shakingサポート、コードベースで統一すべき理由を解説。 - [カスタムエラー](/byethrow/ja/guide/best-practices/custom-error.md): Result.fail()で使うカスタムエラークラスの定義方法と、@praha/error-factoryを活用した型安全なエラー設計のベストプラクティス。 - [パターンマッチング](/byethrow/ja/guide/best-practices/pattern-matching.md): Resultの複数エラー型をts-patternやinstanceof、判別可能なユニオンで型安全にパターンマッチングする方法。 - [LLM 連携](/byethrow/ja/guide/ecosystem/llm-integration.md): @praha/byethrow-docsパッケージを使ってClaude・GitHub Copilot・CursorなどのAIアシスタントにbyethrowのドキュメントを連携する方法。 - [テスト](/byethrow/ja/guide/ecosystem/testing.md): Jest・Vitest・Rstestで@praha/byethrowのResult型をアサートするためのカスタムテストマッチャー。 - [Linter プラグイン](/byethrow/ja/guide/ecosystem/linter/index.md): @praha/byethrow-oxlint は byethrow のベストプラクティスを強制するOxlintプラグイン — インストール、セットアップ、設定、全ルール一覧 - [consistent-namespace](/byethrow/ja/guide/ecosystem/linter/consistent-namespace.md): @praha/byethrow のインポートで Result または R の一貫した名前空間エイリアスを強制するOxlintルール(自動修正対応) - [no-ambiguous-error-type](/byethrow/ja/guide/ecosystem/linter/no-ambiguous-error-type.md): Result/ResultAsync/ResultMaybeAsync のエラー型に unknown・any・Error などの曖昧な型を禁止するOxlintルール - [no-ambiguous-success-type](/byethrow/ja/guide/ecosystem/linter/no-ambiguous-success-type.md): Result/ResultAsync/ResultMaybeAsync の成功型に unknown・any・object などの曖昧な型を禁止するOxlintルール - [no-negated-type-guards](/byethrow/ja/guide/ecosystem/linter/no-negated-type-guards.md): Result.isSuccess() や Result.isFailure() への否定演算子の使用を禁止し、直接の型ガードに自動修正するOxlintルール - [no-throw-in-callback](/byethrow/ja/guide/ecosystem/linter/no-throw-in-callback.md): @praha/byethrow のコールバック内での throw 文を禁止し、Result.fail() の使用を促すOxlintルール - [no-try-catch-in-callback](/byethrow/ja/guide/ecosystem/linter/no-try-catch-in-callback.md): @praha/byethrow のコールバック内での try-catch を禁止し、Result.fn() でのラップを促すOxlintルール - [prefer-result-async](/byethrow/ja/guide/ecosystem/linter/prefer-result-async.md): Promise でラップした Result の代わりに ResultAsync の使用を強制するOxlintルール(自動修正対応) - [prefer-result-matchers](/byethrow/ja/guide/ecosystem/linter/prefer-result-matchers.md): isSuccess/isFailure のboolean assertの代わりに toBeSuccess()/toBeFailure() マッチャーの使用を強制するOxlintルール(自動修正対応) - [prefer-result-maybe-async](/byethrow/ja/guide/ecosystem/linter/prefer-result-maybe-async.md): Result と ResultAsync のユニオン型の代わりに ResultMaybeAsync の使用を強制するOxlintルール(自動修正対応) ## 実装例 - [package.json を解析する](/byethrow/ja/examples/parse-package-json.md): @praha/byethrowを使ってpackage.jsonファイルをパースし、エラーをResult型で安全に処理する実装例。 - [API を実行する CLI](/byethrow/ja/examples/api-request-cli.md): @praha/byethrowを使ってCLIアプリからAPIリクエストを行い、発生しうるエラーを適切に処理する実装例。 ## APIリファレンス - [byethrow](/byethrow/ja/api/index.md) - [Namespace: Result](/byethrow/ja/api/modules/Result.md): Re-exports core Result-handling utilities under two convenient namespaces: - [Type Alias: Failure](/byethrow/ja/api/types/Result.Failure.md): Represents a failed result. - [Type Alias: InferFailure](/byethrow/ja/api/types/Result.InferFailure.md): Infers the Failure value type `E` from a Result or a function returning a Result. - [Type Alias: InferSuccess](/byethrow/ja/api/types/Result.InferSuccess.md): Infers the Success value type `T` from a Result or a function returning a Result. - [Type Alias: Result](/byethrow/ja/api/types/Result.Result.md): A union type representing either a success or a failure. - [Type Alias: ResultAsync](/byethrow/ja/api/types/Result.ResultAsync.md): An asynchronous variant of Result, wrapped in a `Promise`. - [Type Alias: ResultFor](/byethrow/ja/api/types/Result.ResultFor.md): Resolves to the appropriate Result type (sync or async) based on the input type. - [Type Alias: ResultMaybeAsync](/byethrow/ja/api/types/Result.ResultMaybeAsync.md): A result that may be either synchronous or asynchronous. - [Type Alias: Success](/byethrow/ja/api/types/Result.Success.md): Represents a successful result. - [Function: andThen()](/byethrow/ja/api/functions/Result.andThen.md): Chains the next computation using the success value of a Result or ResultAsync. If the original result is a Failure, it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is. - [Function: andThrough()](/byethrow/ja/api/functions/Result.andThrough.md): Runs an additional computation using the success value of a Result or ResultAsync, but **returns the original result** if the additional computation is successful. - [Function: assertFailure()](/byethrow/ja/api/functions/Result.assertFailure.md): Asserts that a Result or ResultAsync is a Failure and returns it. This function requires that the result's success type is `never`, meaning the result is guaranteed to be a Failure at the type level. If the result is a Success at runtime, throws an error. - [Function: assertSuccess()](/byethrow/ja/api/functions/Result.assertSuccess.md): Asserts that a Result or ResultAsync is a Success and returns it. This function requires that the result's error type is `never`, meaning the result is guaranteed to be a Success at the type level. If the result is a Failure at runtime, throws an error. - [Function: bind()](/byethrow/ja/api/functions/Result.bind.md): Chains another Result-producing computation and **merges its success value** into the existing object under the specified key. - [Function: collect()](/byethrow/ja/api/functions/Result.collect.md): Processes multiple Result or ResultAsync values into a single result. If all results are Success, returns a Success containing all values. If any result is a Failure, returns a Failure containing an array of all errors. - [Function: do()](/byethrow/ja/api/functions/Result.do.md): Alias for `succeed({})`. Commonly used as a neutral base value in functional chains or monadic pipelines. - [Function: fail()](/byethrow/ja/api/functions/Result.fail.md): Creates a Failure result from a given error. - [Function: fn()](/byethrow/ja/api/functions/Result.fn.md): Wraps a function that may throw and returns a new function that returns a Result or ResultAsync. - [Function: inspect()](/byethrow/ja/api/functions/Result.inspect.md): Executes a side effect function on the success value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state. - [Function: inspectError()](/byethrow/ja/api/functions/Result.inspectError.md): Executes a side effect function on the error value of a Result or ResultAsync, without modifying the original result. This is useful for debugging, logging, or performing other side effects while maintaining the original value and error state. - [Function: isFailure()](/byethrow/ja/api/functions/Result.isFailure.md): Type guard to check if a Result is a Failure. - [Function: isResult()](/byethrow/ja/api/functions/Result.isResult.md): Type guard to check if a value is a Result. - [Function: isSuccess()](/byethrow/ja/api/functions/Result.isSuccess.md): Type guard to check if a Result is a Success. - [Function: map()](/byethrow/ja/api/functions/Result.map.md): Applies a transformation function to the success value of a Result or ResultAsync. If the input is a Failure, it will be returned unchanged. - [Function: mapError()](/byethrow/ja/api/functions/Result.mapError.md): Applies a transformation function to the error value of a Result or ResultAsync. If the input is a Success, it will be returned unchanged. - [Function: orElse()](/byethrow/ja/api/functions/Result.orElse.md): Chains the next computation using the error value of a Result or ResultAsync. If the original result is a Success, it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is. - [Function: orThrough()](/byethrow/ja/api/functions/Result.orThrough.md): Runs an additional computation using the error value of a Result or ResultAsync, but **returns the original failure** if the additional computation is successful. - [Function: parse()](/byethrow/ja/api/functions/Result.parse.md): Parses a value using a Standard Schema compatible schema. Returns a Result with the parsed value on success or validation errors on failure. - [Function: pipe()](/byethrow/ja/api/functions/Result.pipe.md): Applies a sequence of functions to a value, from left to right. - [Function: sequence()](/byethrow/ja/api/functions/Result.sequence.md): Processes multiple Result or ResultAsync values into a single result. If all results are Success, returns a Success containing all values. If any result is a Failure, immediately stops processing and returns a Failure with that single error. - [Function: succeed()](/byethrow/ja/api/functions/Result.succeed.md): Creates a Success result from a given value. - [Function: try()](/byethrow/ja/api/functions/Result.try.md): Executes a function that may throw and wraps the result in a Result or ResultAsync. - [Function: unwrap()](/byethrow/ja/api/functions/Result.unwrap.md): Extracts the success value from a Result or ResultAsync. - [Function: unwrapError()](/byethrow/ja/api/functions/Result.unwrapError.md): Extracts the error value from a Result or ResultAsync.