require format/message string for invariant (#44098)

* require format/message string for invariant

* works on 2.2.4 (latest)
This commit is contained in:
Turadg Aleahmad 2020-04-23 09:19:01 -07:00 committed by GitHub
parent c04129c8aa
commit b563b0da59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
// Type definitions for invariant 2.2.0
// Type definitions for invariant 2.2.4
// Project: https://github.com/zertosh/invariant
// Definitions by: MichaelBennett <https://github.com/bennett000>
// dtinth <https://github.com/dtinth>
@ -12,8 +12,8 @@ export as namespace invariant;
declare namespace invariant {
interface InvariantStatic {
(testValue:false, format?:string, ...extra:any[]):never;
(testValue:any, format?:string, ...extra:any[]):void;
(testValue:false, format:string, ...extra:any[]):never;
(testValue:any, format:string, ...extra:any[]):void;
}
}

View File

@ -1,9 +1,11 @@
import invariant = require("invariant");
// 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
@ -22,4 +24,4 @@ invariant('', 'Some other error');
invariant(true, 'Error, error, read all about it', 37, {}, 'hello');
// $ExpectType {}
({} as {} | undefined) || invariant(false, 'a is undefined');
({} as {} | undefined) || invariant(false, 'a is undefined');

View File

@ -5,7 +5,7 @@ export as namespace invariant;
declare namespace invariant {
interface InvariantStatic {
(testValue: false, format?: string, ...extra: any[]): never;
(testValue: any, format?: string, ...extra: any[]): asserts testValue;
(testValue: false, format: string, ...extra: any[]): never;
(testValue: any, format: string, ...extra: any[]): asserts testValue;
}
}

View File

@ -8,9 +8,11 @@ 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