Skip to content

isErrorLike

Checks whether a value is structurally an ErrorResult. This helper is used internally by Jane’s result helpers and validators to safely detect error objects without throwing or mutating input.

An ErrorResult is defined as an object with:

  • ok: false
  • field: string
  • message: string

Performs a strict structural check and never throws.

Signature

function isErrorLike(value: unknown): value is ErrorResult

Parameters

Returns

Behavior

  • Pure function: no side effects.
  • Never throws and never mutates input.
  • Performs a strict structural check.
  • Extra fields are allowed but irrelevant.
  • Missing or incorrectly typed fields cause the check to fail.
  • Does not coerce values.

Examples

isErrorLike(createError("username", "Required"))
// true

isErrorLike({ ok: false, field: "x", message: "Bad" })
// true

isErrorLike({ ok: false })
// false

isErrorLike(null)
// false

isErrorLike("not an object")
// false

Notes

  • Intentionally strict: all required fields must be present and correctly typed.
  • It does not validate message formats or field naming conventions.
  • Useful for narrowing unknown values in pipelines.
  • It is safe to use anywhere in Jane’s validation and normalization flow.