Skip to content

Commit d92d0a7

Browse files
committed
feat!: improve definition for type safety
1 parent 857646f commit d92d0a7

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/node_modules/@stdlib/utils/if-else/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* var z = ifelse( randu() > 0.5, 1.0, -1.0 );
3333
* // returns <number>
3434
*/
35-
declare function ifelse( bool: boolean, x: any, y: any ): any;
35+
declare function ifelse<T, U>( bool: boolean, x: T, y: U ): T | U;
3636

3737

3838
// EXPORTS //

lib/node_modules/@stdlib/utils/if-else/docs/types/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ import ifelse = require( './index' );
2323

2424
// The function returns either the `x` or `y` value...
2525
{
26-
ifelse( true, 0, 1 ); // $ExpectType any
27-
ifelse( true, 'a', 'b' ); // $ExpectType any
28-
ifelse( false, 0, 1 ); // $ExpectType any
29-
ifelse( false, 'a', 'b' ); // $ExpectType any
26+
ifelse( true, 0, 1 ); // $ExpectType 0 | 1
27+
ifelse( true, 'a', 'b' ); // $ExpectType "a" | "b"
28+
ifelse( false, 0, 1 ); // $ExpectType 0 | 1
29+
ifelse( false, 'a', 'b' ); // $ExpectType "a" | "b"
3030
}
3131

3232
// The compiler throws an error if the function is not provided a boolean as its first argument...

0 commit comments

Comments
 (0)