mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
* Put current version of invariant in the root Previously, the code that supports the oldest version of Typescript was in the root: 3.1 and below. Newer versions were in ts*/ subdirectories. This PR puts the newest version in the root, and older versions -- before 3.7 in this case -- in ts*/ subdirectories. This is possible because all supported versions of the Typescript now understand the typesVersions property in package.json. This PR needs a new version of DefinitelyTyped-tools and dtslint, which I will ship soon. It also needs to be brought up to date with master. * delete ts3.7/
32 lines
838 B
TypeScript
32 lines
838 B
TypeScript
import invariant = require("invariant");
|
|
|
|
// has assertion side effect
|
|
declare const val: {a: number} | false;
|
|
// $ExpectError
|
|
val.a === 1;
|
|
invariant(val, 'val must be truthy');
|
|
val.a === 1;
|
|
|
|
// will throw in dev mode (process.env.NODE_ENV !== 'production')
|
|
// $ExpectError
|
|
invariant(true);
|
|
|
|
// will pass in production (process.env.NODE_ENV === 'production')
|
|
// $ExpectError
|
|
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');
|