Skip to content

Commit

Permalink
fix: replace use of type guards with boolean return type
Browse files Browse the repository at this point in the history
The type narrowing behavior of type guards makes only sense when the
runtime checks match the type guards. For example `value is string`
should be used with `typeof value === 'string'` and not with a function
that checks for whether a value is a snakecase string. In the latter
case, the type guard would incorrectly narrow the type of the value to
`never` for a string that is not snakecase.
  • Loading branch information
Planeshifter committed Feb 28, 2024
1 parent 30112b7 commit b77ddf7
Show file tree
Hide file tree
Showing 29 changed files with 81 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* var bool = isArrayLength( 3.14 );
* // returns false
*/
declare function isArrayLength( value: any ): value is number;
declare function isArrayLength( value: any ): boolean;


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Comparison = 'open' | 'closed';
* var bool = isBetween( 3.14, 3.0, 3.14, 'closed', 'open' );
* // returns false
*/
declare function isBetween( value: any, a: any, b: any, left?: Comparison, right?: Comparison ): value is number;
declare function isBetween( value: any, a: any, b: any, left?: Comparison, right?: Comparison ): boolean;


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

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

/**
* Tests if a value is a number object having a value which is a composite number.
Expand All @@ -80,7 +80,7 @@ interface IsComposite {
* var bool = isComposite.isObject( new Number( 4.0 ) );
* // returns true
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

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

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

/**
* Tests if a value is a number object having a value which is a cube number.
Expand All @@ -80,7 +80,7 @@ interface IsCubeNumber {
* var bool = isCubeNumber.isObject( new Number( 8.0 ) );
* // returns true
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

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

/**
* Tests if a value is a number primitive that is an even number.
Expand All @@ -68,7 +68,7 @@ interface IsEven {
* var bool = isEven.isPrimitive( new Number( -4.0 ) );
* // returns false
*/
isPrimitive( value: any ): value is number;
isPrimitive( value: any ): boolean;

/**
* Tests if a value is a number object that is an even number.
Expand All @@ -84,7 +84,7 @@ interface IsEven {
* var bool = isEven.isObject( new Number( 4.0 ) );
* // returns true
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

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

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

/**
* Tests if a value is a number object having a finite value.
Expand All @@ -76,7 +76,7 @@ interface IsFinite {
* var bool = isFinite.isObject( new Number( 3.0 ) );
* // returns true
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

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

/**
* Tests if a value is a number primitive having an infinite value.
Expand All @@ -60,7 +60,7 @@ interface IsInfinite {
* var bool = isInfinite.isPrimitive( new Number( -1.0/0.0 ) );
* // returns false
*/
isPrimitive( value: any ): value is number;
isPrimitive( value: any ): boolean;

/**
* Tests if a value is a number object having an infinite value.
Expand All @@ -76,7 +76,7 @@ interface IsInfinite {
* var bool = isInfinite.isObject( new Number( 1.0/0.0 ) );
* // returns true
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

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

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

/**
* Tests if a value is a number object having an integer value.
Expand All @@ -76,7 +76,7 @@ interface IsInteger {
* var bool = isInteger.isObject( new Number( 3.0 ) );
* // returns true
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

/**
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 ): value is number | Number;
( value: any ): boolean;

/**
* 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 ): value is number;
isPrimitive( value: any ): boolean;

/**
* 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 ): value is Number;
isObject( value: any ): boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface isNegativeFinite {
* var bool = isNegativeFinite( -1.0/0.0 );
* // returns false
*/
( value: number | Number ): value is number | Number;
( value: number | Number ): boolean;

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

/**
* Tests if a value is a number object having a negative value.
Expand All @@ -84,7 +84,7 @@ interface isNegativeFinite {
* var bool = isNegativeFinite.isObject( new Number( -3.0 ) );
* // returns true
*/
isObject( value: number | Number ): value is Number;
isObject( value: number | Number ): boolean;
}

/**
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 ): value is number | Number;
( value: any ): boolean;

/**
* 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 ): value is number;
isPrimitive( value: any ): boolean;

/**
* 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 ): value is Number;
isObject( value: any ): boolean;
}

/**
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 ): value is number | Number;
( value: any ): boolean;

/**
* 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 ): value is number;
isPrimitive( value: any ): boolean;

/**
* 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 ): value is Number;
isObject( value: any ): boolean;
}

/**
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 ): value is number | Number;
( value: any ): boolean;

/**
* 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 ): value is number;
isPrimitive( value: any ): boolean;

/**
* 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 ): value is Number;
isObject( value: any ): boolean;
}

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

/**
* Tests if a value is a number primitive having a nonnegative finite value.
Expand All @@ -76,7 +76,7 @@ interface IsNonNegativeFinite {
* var bool = isNonNegativeFinite( 1.0/0.0 );
* // returns false
*/
isPrimitive( value: any ): value is number;
isPrimitive( value: any ): boolean;

/**
* Tests if a value is a finite number object having a nonnegative value.
Expand All @@ -100,7 +100,7 @@ interface IsNonNegativeFinite {
* var bool = isNonNegativeFinite( 1.0/0.0 );
* // returns false
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

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

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

/**
* Tests if a value is a number object having a nonnegative integer value.
Expand All @@ -80,7 +80,7 @@ interface IsNonNegativeInteger {
* var bool = isNonNegativeInteger.isObject( new Number( 3.0 ) );
* // returns true
*/
isObject( value: any ): value is Number;
isObject( value: any ): boolean;
}

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

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

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

/**
Expand Down
Loading

0 comments on commit b77ddf7

Please sign in to comment.