Skip to content

Latest commit

 

History

History

invariant

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

An invariant function, which takes a condition and a optional message value, and throw an error when the given condition fails.

Install

  • npm

    npm install --save @guanghechen/invariant
  • yarn

    yarn add @guanghechen/invariant

Usage

  • Syntax

    function invariant(
      condition: boolean,
      message?: string | (() => string),
    ): asserts condition
  • Demo

    import invariant from '@guanghechen/invariant'
    
    invariant(typeof window !== 'undefined', '`window` is not defined.')
    invariant(typeof window !== 'undefined', () => '`window` is not defined:' + window)

Related