diff --git a/invariant/invariant-tests.ts b/invariant/invariant-tests.ts new file mode 100644 index 000000000..06a4e9b4e --- /dev/null +++ b/invariant/invariant-tests.ts @@ -0,0 +1,22 @@ +/// + +// 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'); diff --git a/invariant/invariant.d.ts b/invariant/invariant.d.ts new file mode 100644 index 000000000..6ca967c68 --- /dev/null +++ b/invariant/invariant.d.ts @@ -0,0 +1,17 @@ +// Type definitions for invariant 2.2.0 +// Project: https://github.com/zertosh/invariant +// Definitions by: MichaelBennett +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare let invariant:invariant.InvariantStatic; + +declare module "invariant" { + export = invariant; +} + +declare module invariant { + interface InvariantStatic { + (testValue:any, format?:string, ...extra:any[]):void; + } +} +