Skip to content

Variable: isResult()

readonly isResult: (value) => value is Result<unknown, unknown>

Defined in: core/factories.ts:435

Checks if a value is a Result instance (Ok or Err).

Useful for type guards and runtime checking when you receive values from external sources or dynamic APIs.

Parameters

value

unknown

Value to check

Returns

value is Result<unknown, unknown>

true if the value is a Result instance

Examples

ts
// Basic checking
Result.isResult(Result.ok(1))        // true
Result.isResult(Result.err('fail'))  // true
Result.isResult(42)                  // false
Result.isResult({ ok: 1 })           // false
ts
// Usage as type guard
function process(value: unknown) {
  if (Result.isResult(value)) {
    // TypeScript knows value is Result<unknown, unknown>
    return value.isOk() ? value.unwrap() : value.unwrapErr()
  }

  return value
}
ts
// API input validation
function handleResponse(data: unknown) {
  if (!Result.isResult(data)) {
    throw new Error('Invalid response')
  }

  return data
}