Converts tests to TypeScript (#300)

This commit is contained in:
Jaco Greeff
2019-02-14 10:48:08 +01:00
committed by GitHub
parent 2a14a8b553
commit 1e6eb2c283
158 changed files with 89 additions and 183 deletions
+3 -2
View File
@@ -7,9 +7,10 @@ import isFunction from './is/function';
type MessageFn = () => string;
type Falsy = null | undefined | false | 0 | ''; // No NaN type
/**
* @name assert
* @signature assert (test: any, message: string | () => string, code: number = ExtError.CODES.ASSERT, data: any): void
* @summary Checks for a valid test, if not ExtError is thrown.
* @description
* Checks that `test` is a truthy value. If value is falsy (`null`, `undefined`, `false`, ...), it throws an ExtError with the supplied `message` and an optional `code` and `data`. When `test` passes, `true` is returned.
@@ -24,7 +25,7 @@ type MessageFn = () => string;
* assert(false, () => 'message'); // ExtError with 'message'
* ```
*/
export default function assert (test: any, message: string | MessageFn, code: number = ExtError.CODES.ASSERT, data?: any): boolean {
export default function assert<T> (test: Falsy | T, message: string | MessageFn, code: number = ExtError.CODES.ASSERT, data?: any): test is T {
if (test) {
return true;
}