Converts tests to TypeScript (#300)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user