Skip to content

Function.mapError

github-actions[bot] edited this page Nov 18, 2026 · 13 revisions

umt / mapError

Function: mapError()

mapError<V, E, F>(result, function_): Result<V, F>

Defined in: Error/mapError.ts:22

Transforms the error inside a failed Result using the provided mapping function. If the Result is a success, it is returned unchanged.

Type Parameters

V

V

E

E

F

F

Parameters

result

Result<V, E>

The Result to transform.

function_

(error) => F

The function to apply to the error.

Returns

Result<V, F>

A new Result with the transformed error, or the original success.

Example

const error = { type: "error", error: "not found" } as const;
mapError(error, (message) => new Error(message));
// { type: "error", error: Error("not found") }

const success = { type: "success", value: 5 } as const;
mapError(success, (message: string) => new Error(message));
// { type: "success", value: 5 }

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally