Errors
/ API Reference
Errors
/ API Reference

invariant

A helper function that throws an error if the condition is not met.

The Gist

import { invariant } from '@weser/errors'

function parseData(data: any) {
  invariant(data, 'Data is required.')
  invariant(typeof data === 'object', 'Data must be an object.')

  return data.raw
}

Parameters

PropertyTypeDescription
conditionbooleanA boolean indicating whether the invariant is valid.
messagestringA message to display when the invariant is not valid.
On this page