mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
This allows patterns such as this when strict null checks are on:
let instance: Thing | undefined;
function getInstance(): Thing {
return instance || invariant(false, "`instance` not instantiated");
}
25 lines
736 B
TypeScript
25 lines
736 B
TypeScript
import invariant = require("invariant");
|
|
|
|
// will throw in dev mode (process.env.NODE_ENV !== 'production')
|
|
invariant(true);
|
|
|
|
// will pass in production (process.env.NODE_ENV === 'production')
|
|
invariant(true);
|
|
|
|
// will pass in dev mode and production mode
|
|
invariant(true, 'Error, error, read all about it');
|
|
|
|
// will throw in dev mode, and production mode
|
|
invariant(false, 'Some other error');
|
|
|
|
// will throw in dev mode, and production mode
|
|
invariant(0, 'Some other error');
|
|
|
|
// will throw in dev mode, and production mode
|
|
invariant('', 'Some other error');
|
|
|
|
// handles extra variables
|
|
invariant(true, 'Error, error, read all about it', 37, {}, 'hello');
|
|
|
|
// $ExpectType {}
|
|
({} as {} | undefined) || invariant(false, 'a is undefined'); |