tryError Documentation

Function: isErr()
Function

```ts function isErr<T, E>(result): result is E; ``` Defined in: [sync.ts:331](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/sync.ts#L331) Check if a TryResult is an error Type predicate that narrows the type

tryError API Documentation v0.0.1-alpha.1


tryError API Documentation / isErr

Function: isErr()

function isErr<T, E>(result): result is E;

Defined in: sync.ts:331

Check if a TryResult is an error Type predicate that narrows the type

Type Parameters

T

T

E

E extends TryError<string>

Parameters

result

TryResult<T, E>

The result to check

Returns

result is E

True if result is an error

Example

const result = trySync(() => JSON.parse(jsonString));
if (isErr(result)) {
  // result is narrowed to error type
  console.error(result.message);
}