Skip to content

Function: isErr()

Call Signature

isErr<T>(result): result is Err<T>

Defined in: index.ts:330

Type guard that checks if a Result is an Err (error) result.

Type Parameters

T

T

Parameters

result

Result<unknown, T>

The Result to check

Returns

result is Err<T>

True if the result is Err, false if it's Ok

Example

typescript
const r: Result<string, Error> = err(new Error("failed"));

if (isErr(r)) {
  // r is now typed as Err<Error>
  console.log(result.error.message);
}

Call Signature

isErr<R>(result): result is Extract<R, Err<any>>

Defined in: index.ts:331

Type guard that checks if a Result is an Err (error) result.

Type Parameters

R

R extends UnknownResult

Parameters

result

R

The Result to check

Returns

result is Extract<R, Err<any>>

True if the result is Err, false if it's Ok

Example

typescript
const r: Result<string, Error> = err(new Error("failed"));

if (isErr(r)) {
  // r is now typed as Err<Error>
  console.log(result.error.message);
}