Skip to content

Commit

Permalink
feat: use type predicates for narrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Planeshifter committed Jun 28, 2023
1 parent 886d7f9 commit fc5b401
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* bool = isNullArray( [NaN,2,null] );
* // returns false
*/
declare function isNullArray( value: any ): boolean;
declare function isNullArray( value: any ): value is ArrayLike<null>;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* bool = isNull( true );
* // returns false
*/
declare function isNull( value: any ): boolean;
declare function isNull( value: any ): value is null;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IsNumberArray {
* var bool = isNumberArray( [ -3.0, '3.0' ] );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is ArrayLike<number | Number>;

/**
* Tests if a value is an array-like object containing only number primitives.
Expand All @@ -56,7 +56,7 @@ interface IsNumberArray {
* var bool = isNumberArray.primitives( [ -3.0, new Number(-1.0) ] );
* // returns false
*/
primitives( value: any ): boolean;
primitives( value: any ): value is ArrayLike<number>;

/**
* Tests if a value is an array-like object containing only number objects.
Expand All @@ -76,7 +76,7 @@ interface IsNumberArray {
* var bool = isNumberArray.objects( [ 3.0, new Number(-1.0) ] );
* // returns false
*/
objects( value: any ): boolean;
objects( value: any ): value is ArrayLike<Number>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IsNumber {
* var bool = isNumber( null );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is number | Number;

/**
* Tests if a value is a number primitive.
Expand All @@ -64,7 +64,7 @@ interface IsNumber {
* var bool = isNumber.isPrimitive( new Number( 3.14 ) );
* // returns false
*/
isPrimitive( value: any ): boolean;
isPrimitive( value: any ): value is number;

/**
* Tests if a value is a number object.
Expand All @@ -80,7 +80,7 @@ interface IsNumber {
* var bool = isNumber.isObject( new Number( 3.14 ) );
* // returns true
*/
isObject( value: any ): boolean;
isObject( value: any ): value is Number;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* bool = isNumericArray( [ '1', '2', '3' ] );
* // returns false
*/
declare function isNumericArray( v: any ): boolean;
declare function isNumericArray( v: any ): v is ArrayLike<number>;


// EXPORTS //
Expand Down

0 comments on commit fc5b401

Please sign in to comment.