Skip to content

Type Alias: UnwrapErr<T>

UnwrapErr<T> = InferErr<T> extends never ? never : InferErr<T> extends Err<infer R> ? R : never

Defined in: index.ts:182

Extracts the error type from Err results, handling promises and function return types.

This utility extracts the inner error type from error results, effectively "unwrapping" the Err wrapper to get to the actual error type. Returns never if no Err types are found in the input type.

Type Parameters

T

T

The type to extract error from

Example

typescript
type T1 = UnwrapErr<Result<string, Error>>; // Error
type T2 = UnwrapErr<Promise<Result<string, Error>>>; // Error
type T3 = UnwrapErr<() => Result<number, string>>; // string
type T4 = UnwrapErr<() => Promise<Result<User, ApiError>>>; // ApiError