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 d88aba7 commit 815ed35
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IsSafeIntegerArray {
* var bool = isSafeIntegerArray( [ -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 primitive safe integer values.
Expand All @@ -56,7 +56,7 @@ interface IsSafeIntegerArray {
* var bool = isSafeIntegerArray.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 safe integer values.
Expand All @@ -76,7 +76,7 @@ interface IsSafeIntegerArray {
* var bool = isSafeIntegerArray.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 IsSafeInteger {
* var bool = isSafeInteger( null );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is number | Number;

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


/**
Expand All @@ -81,7 +81,7 @@ interface IsSafeInteger {
* var bool = isSafeInteger.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 @@ -40,7 +40,7 @@
* var bool = isSemVer( null );
* // returns false
*/
declare function isSemVer( value: any ): boolean;
declare function isSemVer( value: any ): value is string;


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


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


// EXPORTS //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface IsSquareTriangularNumber {
* var bool = isSquareTriangularNumber( 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 square triangular number.
Expand All @@ -64,7 +64,7 @@ interface IsSquareTriangularNumber {
* var bool = isSquareTriangularNumber.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 square triangular number.
Expand All @@ -80,7 +80,7 @@ interface IsSquareTriangularNumber {
* var bool = isSquareTriangularNumber.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 = isStartcase( 'Beep and Boop' );
* // returns false
*/
declare function isStartcase( value: any ): boolean;
declare function isStartcase( value: any ): value is string;


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

/**
* Tests if a value is an array containing only string primitives.
Expand All @@ -52,7 +52,7 @@ interface IsStringArray {
* var bool = isStringArray.primitives( [ 'abc', new String( 'def' ) ] );
* // returns false
*/
primitives( value: any ): boolean;
primitives( value: any ): value is ArrayLike<string>;

/**
* Tests if a value is an array containing only `String` objects.
Expand All @@ -68,7 +68,7 @@ interface IsStringArray {
* var bool = isStringArray.objects( [ new String( 'abc' ), 'def' ] );
* // returns false
*/
objects( value: any ): boolean;
objects( value: any ): value is ArrayLike<String>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IsString {
* var bool = isString( 'beep' );
* // returns true
*/
( value: any ): boolean;
( value: any ): value is string | String;

/**
* Tests if a value is a string primitive.
Expand All @@ -52,7 +52,7 @@ interface IsString {
* var bool = isString.isPrimitive( new String( 'beep' ) );
* // returns false
*/
isPrimitive( value: any ): boolean;
isPrimitive( value: any ): value is string;

/**
* Tests if a value is a string object.
Expand All @@ -68,7 +68,7 @@ interface IsString {
* var bool = isString.isObject( 'beep' );
* // returns false
*/
isObject( value: any ): boolean;
isObject( value: any ): value is String;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface IsSymbolArray {
* var bool = isSymbolArray( [ Symbol( 'abc' ), 'def' ] );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is ArrayLike<symbol | Symbol>;

/**
* Tests if a value is an array-like object containing only `symbol` primitives.
Expand All @@ -60,7 +60,7 @@ interface IsSymbolArray {
* var bool = isSymbolArray.primitives( [ Symbol( 'abc' ), Object( Symbol( 'def' ) ) ] );
* // returns false
*/
primitives( value: any ): boolean;
primitives( value: any ): value is ArrayLike<symbol>;

/**
* Tests if a value is an array-like object containing only `Symbol` objects.
Expand All @@ -81,7 +81,7 @@ interface IsSymbolArray {
* var bool = isSymbolArray.objects( [ Symbol( 'abc' ), Symbol( 'def' ) ] );
* // returns false
*/
objects( value: any ): boolean;
objects( value: any ): value is ArrayLike<Symbol>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface IsSymbol {
* var bool = isSymbol( {} );
* // returns false
*/
( value: any ): boolean;
( value: any ): value is symbol | Symbol;

/**
* Tests if a value is a symbol primitive.
Expand All @@ -68,7 +68,7 @@ interface IsSymbol {
* var bool = isSymbol.isPrimitive( {} );
* // returns false
*/
isPrimitive( value: any ): boolean;
isPrimitive( value: any ): value is symbol;

/**
* Tests if a value is a symbol object.
Expand All @@ -92,7 +92,7 @@ interface IsSymbol {
* var bool = isSymbol.isObject( {} );
* // returns false
*/
isObject( value: any ): boolean;
isObject( value: any ): value is Symbol;
}

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


// EXPORTS //
Expand Down

0 comments on commit 815ed35

Please sign in to comment.