Skip to content

Commit b121c69

Browse files
committed
feat: use type predicates for narrowing
1 parent 3c153c4 commit b121c69

File tree

11 files changed

+19
-17
lines changed

11 files changed

+19
-17
lines changed

lib/node_modules/@stdlib/assert/is-between-array/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type Comparison = 'open' | 'closed';
5858
* var bool = isBetweenArray( arr, 3.0, 4.0, 'closed', 'open' );
5959
* // returns false
6060
*/
61-
declare function isBetweenArray( value: any, a: any, b: any, left?: Comparison, right?: Comparison ): boolean; // tslint-disable-line max-line-length
61+
declare function isBetweenArray( value: any, a: any, b: any, left?: Comparison, right?: Comparison ): value is ArrayLike<number>; // tslint-disable-line max-line-length
6262

6363

6464
// EXPORTS //

lib/node_modules/@stdlib/assert/is-between/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Comparison = 'open' | 'closed';
5757
* var bool = isBetween( 3.14, 3.0, 3.14, 'closed', 'open' );
5858
* // returns false
5959
*/
60-
declare function isBetween( value: any, a: any, b: any, left?: Comparison, right?: Comparison ): boolean; // tslint-disable-line max-line-length
60+
declare function isBetween( value: any, a: any, b: any, left?: Comparison, right?: Comparison ): value is number; // tslint-disable-line max-line-length
6161

6262

6363
// EXPORTS //

lib/node_modules/@stdlib/assert/is-bigint/docs/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ interface IsBigInt {
4444
* var bool = isBigInt( {} );
4545
* // returns false
4646
*/
47-
( value: any ): boolean;
47+
( value: any ): value is bigint | BigInt;
4848

4949
/**
5050
* Tests if a value is a BigInt primitive.
@@ -68,7 +68,7 @@ interface IsBigInt {
6868
* var bool = isBigInt.isPrimitive( {} );
6969
* // returns false
7070
*/
71-
isPrimitive( value: any ): boolean;
71+
isPrimitive( value: any ): value is bigint;
7272

7373
/**
7474
* Tests if a value is a BigInt object.
@@ -92,7 +92,7 @@ interface IsBigInt {
9292
* var bool = isBigInt.isObject( {} );
9393
* // returns false
9494
*/
95-
isObject( value: any ): boolean;
95+
isObject( value: any ): value is BigInt;
9696
}
9797

9898
/**

lib/node_modules/@stdlib/assert/is-bigint64array/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* var bool = isBigInt64Array( [] );
3333
* // returns false
3434
*/
35-
declare function isBigInt64Array( value: any ): boolean;
35+
declare function isBigInt64Array( value: any ): value is BigInt64Array;
3636

3737

3838
// EXPORTS //

lib/node_modules/@stdlib/assert/is-biguint64array/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* var bool = isBigUint64Array( [] );
3333
* // returns false
3434
*/
35-
declare function isBigUint64Array( value: any ): boolean;
35+
declare function isBigUint64Array( value: any ): value is BigUint64Array;
3636

3737

3838
// EXPORTS //

lib/node_modules/@stdlib/assert/is-binary-string/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* var bool = isBinaryString( '' );
3737
* // returns false
3838
*/
39-
declare function isBinaryString( value: any ): boolean;
39+
declare function isBinaryString( value: any ): value is string;
4040

4141

4242
// EXPORTS //

lib/node_modules/@stdlib/assert/is-blank-string/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
* var bool = isBlankString( 'beep' );
4545
* // returns false
4646
*/
47-
declare function isBlankString( value: any ): boolean;
47+
declare function isBlankString( value: any ): value is string;
4848

4949

5050
// EXPORTS //

lib/node_modules/@stdlib/assert/is-boolean-array/docs/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface IsBooleanArray {
3636
* var bool = isBooleanArray( [ true, 'abc', false ] );
3737
* // returns false
3838
*/
39-
( value: any ): boolean;
39+
( value: any ): value is Array<boolean|Boolean>;
4040

4141
/**
4242
* Tests if a value is an array-like object containing only boolean primitives.
@@ -54,7 +54,7 @@ interface IsBooleanArray {
5454
* var bool = isBooleanArray.primitives( [ false, new Boolean( true ) ] );
5555
* // returns false
5656
*/
57-
primitives( value: any ): boolean;
57+
primitives( value: any ): value is Array<boolean>;
5858

5959
/**
6060
* Tests if a value is an array-like object containing only Boolean objects.
@@ -74,7 +74,7 @@ interface IsBooleanArray {
7474
* var bool = isBooleanArray.objects( [ new Boolean( false ), true ] );
7575
* // returns false
7676
*/
77-
objects( value: any ): boolean;
77+
objects( value: any ): value is Array<Boolean>;
7878
}
7979

8080
/**

lib/node_modules/@stdlib/assert/is-boolean/docs/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ interface IsBoolean {
4848
* var bool = isBoolean( new Boolean( true ) );
4949
* // returns true
5050
*/
51-
( value: any ): boolean;
51+
( value: any ): value is boolean | Boolean;
5252

5353
/**
5454
* Tests if a value is a boolean primitive.
@@ -70,7 +70,7 @@ interface IsBoolean {
7070
* var bool = isBoolean.isPrimitive( new Boolean( true ) );
7171
* // returns false
7272
*/
73-
isPrimitive( value: any ): boolean;
73+
isPrimitive( value: any ): value is boolean;
7474

7575
/**
7676
* Tests if a value is a boolean object.
@@ -88,7 +88,7 @@ interface IsBoolean {
8888
* var bool = isBoolean.isObject( new Boolean( false ) );
8989
* // returns true
9090
*/
91-
isObject( value: any ): boolean;
91+
isObject( value: any ): value is Boolean;
9292
}
9393

9494
/**

lib/node_modules/@stdlib/assert/is-boxed-primitive/docs/types/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* var bool = isBoxedPrimitive( Symbol( 'beep' ) );
5151
* // returns false
5252
*/
53-
declare function isBoxedPrimitive( value: any ): boolean;
53+
declare function isBoxedPrimitive( value: any ): value is String | Number | Boolean | Symbol; // tslint:disable-line:max-line-length
5454

5555

5656
// EXPORTS //

lib/node_modules/@stdlib/assert/is-buffer/docs/types/index.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
// TypeScript Version: 2.0
2020

21+
/// <reference types="@types/node"/>
22+
2123
/**
2224
* Tests if a value is a Buffer instance.
2325
*
@@ -40,7 +42,7 @@
4042
* var v = isBuffer( [] );
4143
* // returns false
4244
*/
43-
declare function isBuffer( value: any ): boolean;
45+
declare function isBuffer( value: any ): value is Buffer;
4446

4547

4648
// EXPORTS //

0 commit comments

Comments
 (0)