DefinitelyTyped/types/invariant/invariant-tests.ts
Nathan Shively-Sanders c08902966d
Put current version of invariant in the root (#47198)
* 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/
2020-09-01 13:10:11 -07:00

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');