JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8701239
  • Score
    100M100P100Q217677F
  • License MIT

Type-safe implementation of invariant with positionals.

Package Exports

  • outvariant

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (outvariant) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

outvariant

Why?

  • Type-safe implementation of invariant. Asserts the given predicate expression so it's treated as non-nullable after the invariant call:
// Regular "invariant":
invariant(user, 'Failed to fetch')
user?.firstName // "user" is possibly undefined

// The glorious "outvariant":
invariant(user, 'Failed to fetch')
user.firstName // OK, "user" exists at this point
  • Positionals support.
invariant(predicate, 'Expected %s but got %s', 'one', false)

Getting started

npm install outvariant
# or
yarn add outvariant
import { invariant } from 'outvariant'

invariant(user, 'Failed to load: expected user, but got %o', user)