Skip to content

Commit f0d4bea

Browse files
committed
Use overloads to describe callback function
1 parent 8524cd9 commit f0d4bea

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/node_modules/@stdlib/iter/map/docs/types/index.d.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,38 @@ import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
2525
// Define a union type representing both iterable and non-iterable iterators:
2626
type Iterator = Iter | IterableIterator;
2727

28+
/**
29+
* Callback function which transforms an iterated value.
30+
*
31+
* @returns callback result
32+
*/
33+
type Nullary = () => any;
34+
35+
/**
36+
* Callback function which transforms an iterated value.
37+
*
38+
* @param value - iterated value
39+
* @returns callback result
40+
*/
41+
type Unary = ( value: any ) => any;
42+
43+
/**
44+
* Callback function which transforms an iterated value.
45+
*
46+
* @param value - iterated value
47+
* @param i - iteration index
48+
* @returns callback result
49+
*/
50+
type Binary = ( value: any, i: number ) => any;
51+
2852
/**
2953
* Callback function which transforms an iterated value.
3054
*
3155
* @param value - iterated value
3256
* @param i - iteration index
3357
* @returns callback result
3458
*/
35-
type Callback = ( value?: any, i?: number ) => any;
59+
type Callback = Nullary | Unary | Binary;
3660

3761
/**
3862
* Returns an iterator which invokes a function for each iterated value.

lib/node_modules/@stdlib/iter/map/docs/types/test.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ function iterator() {
4444
/**
4545
* Callback function.
4646
*
47+
* @param v - iterated value
48+
* @param i - iteration index
4749
* @returns callback result
4850
*/
49-
function fcn() {
50-
return 'beep';
51+
function fcn( v: any, i: number ): any {
52+
if ( i !== i ) {
53+
throw new Error( 'something went wrong' );
54+
}
55+
return v;
5156
}
5257

5358

0 commit comments

Comments
 (0)