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 b14cb4a commit 3aba9d6
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IsNaNArray {
* var bool = isNaNArray( [NaN,2] );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is ArrayLike<number | Number>;

/**
* Tests if a value is an array-like object containing only primitive NaN values.
Expand All @@ -52,7 +52,7 @@ interface IsNaNArray {
* var bool = isNaNArray.primitives( [NaN,NaN,NaN] );
* // returns true
*/
primitives( value: any ): boolean;
primitives( value: any ): value is ArrayLike<number>;

/**
* Tests if a value is an array-like object containing only number objects having NaN values.
Expand All @@ -71,7 +71,7 @@ interface IsNaNArray {
* @example
* var bool = isNaNArray.objects( [NaN,NaN,NaN] );
*/
objects( value: any ): boolean;
objects( value: any ): value is ArrayLike<Number>;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/node_modules/@stdlib/assert/is-nan/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IsNaN {
* var bool = isnan( null );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is number | Number;

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

/**
* Tests if a value is a number object having a value of `NaN`.
Expand All @@ -80,7 +80,7 @@ interface IsNaN {
* var bool = isnan.isObject( new Number( NaN ) );
* // 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 @@ -35,7 +35,7 @@
* bool = isNativeFunction( Date );
* // returns true
*/
declare function isNativeFunction( value: any ): boolean;
declare function isNativeFunction( value: any ): value is Function;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IsNegativeIntegerArray {
* var bool = isNegativeIntegerArray( [ -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 negative primitive integer values.
Expand All @@ -56,7 +56,7 @@ interface IsNegativeIntegerArray {
* var bool = isNegativeIntegerArray.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 having negative integer values.
Expand All @@ -76,7 +76,7 @@ interface IsNegativeIntegerArray {
* var bool = isNegativeIntegerArray.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 @@ -48,7 +48,7 @@ interface IsNegativeInteger {
* var bool = isNegativeInteger( null );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is number | Number;

/**
* Tests if a value is a number primitive having a negative integer value.
Expand All @@ -64,7 +64,7 @@ interface IsNegativeInteger {
* var bool = isNegativeInteger.isPrimitive( new Number( -3.0 ) );
* // returns false
*/
isPrimitive( value: any ): boolean;
isPrimitive( value: any ): value is number;

/**
* Tests if a value is a number object having a negative integer value.
Expand All @@ -80,7 +80,7 @@ interface IsNegativeInteger {
* var bool = isNegativeInteger.isObject( new Number( -3.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 @@ -36,7 +36,7 @@ interface IsNegativeNumberArray {
* var bool = isNegativeNumberArray( [ -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 negative primitive number values.
Expand All @@ -56,7 +56,7 @@ interface IsNegativeNumberArray {
* var bool = isNegativeNumberArray.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 having negative number values.
Expand All @@ -76,7 +76,7 @@ interface IsNegativeNumberArray {
* var bool = isNegativeNumberArray.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 @@ -48,7 +48,7 @@ interface IsNegativeNumber {
* var bool = isNegativeNumber( null );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is number | Number;

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

/**
* Tests if a value is a number object having a negative value.
Expand All @@ -80,7 +80,7 @@ interface IsNegativeNumber {
* var bool = isNegativeNumber.isObject( new Number( -3.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 @@ -52,7 +52,7 @@ interface IsNegativeZero {
* var bool = isNegativeZero( null );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is number | Number;

/**
* Tests if a value is a number primitive equal to negative zero.
Expand All @@ -68,7 +68,7 @@ interface IsNegativeZero {
* var bool = isNegativeZero.isPrimitive( new Number( -0.0 ) );
* // returns false
*/
isPrimitive( value: any ): boolean;
isPrimitive( value: any ): value is number;

/**
* Tests if a value is a number object having a value equal to negative zero.
Expand All @@ -84,7 +84,7 @@ interface IsNegativeZero {
* var bool = isNegativeZero.isObject( new Number( -0.0 ) );
* // returns true
*/
isObject( value: any ): boolean;
isObject( value: any ): value is Number;
}

/**
Expand Down

0 comments on commit 3aba9d6

Please sign in to comment.