Skip to content

Type Alias: UnwrapOk<T>

UnwrapOk<T> = InferOk<T> extends never ? never : InferOk<T> extends Ok<infer R> ? R : never

Defined in: index.ts:163

Extracts the data type from Ok results, handling promises and function return types.

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

Type Parameters

T

T

The type to extract data from

Example

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