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 e2c4238 commit d88aba7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface IsTriangularNumber {
* var bool = isTriangularNumber( null );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is number | Number;

/**
* Tests if a value is a number primitive having a value which is a triangular number.
Expand All @@ -64,7 +64,7 @@ interface IsTriangularNumber {
* var bool = isTriangularNumber.isPrimitive( new Number( 36.0 ) );
* // returns false
*/
isPrimitive( value: any ): boolean;
isPrimitive( value: any ): value is number;

/**
* Tests if a value is a number object having a value which is a triangular number.
Expand All @@ -80,7 +80,7 @@ interface IsTriangularNumber {
* var bool = isTriangularNumber.isObject( new Number( 36.0 ) );
* // 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 = isTruthyArray( [] );
* // returns false
*/
declare function isTruthyArray( value: any ): boolean;
declare function isTruthyArray( value: any ): value is ArrayLike<any>;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* var bool = isTypeError( {} );
* // returns false
*/
declare function isTypeError( value: any ): boolean;
declare function isTypeError( value: any ): value is TypeError;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* var bool = isTypedArrayLength( 3.14 );
* // returns false
*/
declare function isTypedArrayLength( value: any ): boolean;
declare function isTypedArrayLength( value: any ): value is number;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

// TypeScript Version: 2.0

/// <reference types="@stdlib/types"/>

import { TypedArray } from '@stdlib/types/array';

/**
* Tests if a value is a typed array.
*
Expand All @@ -30,7 +34,7 @@
* var bool = isTypedArray( new Int8Array( 10 ) );
* // returns true
*/
declare function isTypedArray( value: any ): boolean;
declare function isTypedArray( value: any ): value is TypedArray;


// EXPORTS //
Expand Down

0 comments on commit d88aba7

Please sign in to comment.