Skip to content

Commit 7bca4a1

Browse files
committed
Auto-generated commit
1 parent 90c1fb8 commit 7bca4a1

File tree

5 files changed

+150
-11
lines changed

5 files changed

+150
-11
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

CHANGELOG.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,80 @@
22

33
> Package changelog.
44
5+
<section class="release" id="unreleased">
6+
7+
## Unreleased (2024-10-14)
8+
9+
<section class="features">
10+
11+
### Features
12+
13+
- [`b74a08a`](https://github.com/stdlib-js/stdlib/commit/b74a08ae1dfc859ac8b9704af27e3c3399ad2da5) - improve type declarations for `utils/map-arguments` [(#2050)](https://github.com/stdlib-js/stdlib/pull/2050)
14+
15+
</section>
16+
17+
<!-- /.features -->
18+
19+
<section class="breaking-changes">
20+
21+
### BREAKING CHANGES
22+
23+
- [`b74a08a`](https://github.com/stdlib-js/stdlib/commit/b74a08ae1dfc859ac8b9704af27e3c3399ad2da5): function signature and return type now more strictly typed
24+
25+
- The mapArguments function now uses generic types instead of 'Function', and its
26+
return type depends on thisArg presence.
27+
Users should review and update their usage of mapArguments, particularly:
28+
- Ensure provided functions match the new, stricter type requirements
29+
- Update any type assertions or checks where mapArguments is used
30+
- Pay special attention to contexts where this binding is significant
31+
32+
</section>
33+
34+
<!-- /.breaking-changes -->
35+
36+
<section class="issues">
37+
38+
### Closed Issues
39+
40+
This release closes the following issue:
41+
42+
[#1087](https://github.com/stdlib-js/stdlib/issues/1087)
43+
44+
</section>
45+
46+
<!-- /.issues -->
47+
48+
<section class="commits">
49+
50+
### Commits
51+
52+
<details>
53+
54+
- [`b74a08a`](https://github.com/stdlib-js/stdlib/commit/b74a08ae1dfc859ac8b9704af27e3c3399ad2da5) - **feat:** improve type declarations for `utils/map-arguments` [(#2050)](https://github.com/stdlib-js/stdlib/pull/2050) _(by Prajwal Kulkarni, Philipp Burckhardt, Prajwal Kulkarni)_
55+
56+
</details>
57+
58+
</section>
59+
60+
<!-- /.commits -->
61+
62+
<section class="contributors">
63+
64+
### Contributors
65+
66+
A total of 2 people contributed to this release. Thank you to the following contributors:
67+
68+
- Philipp Burckhardt
69+
- Prajwal Kulkarni
70+
71+
</section>
72+
73+
<!-- /.contributors -->
74+
75+
</section>
76+
77+
<!-- /.release -->
78+
579
<section class="release" id="v0.2.2">
680

781
## 0.2.2 (2024-07-27)

CONTRIBUTORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com>
2828
Frank Kovacs <fran70kk@gmail.com>
2929
Golden Kumar <103646877+AuenKr@users.noreply.github.com>
3030
Gunj Joshi <gunjjoshi8372@gmail.com>
31+
Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com>
3132
HarshaNP <96897754+GittyHarsha@users.noreply.github.com>
3233
Harshita Kalani <harshitakalani02@gmail.com>
3334
Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
@@ -94,6 +95,7 @@ Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com>
9495
Tufailahmed Bargir <142114244+Tufailahmed-Bargir@users.noreply.github.com>
9596
Utkarsh <http://utkarsh11105@gmail.com>
9697
Utkarsh Raj <rajutkarsh2505@gmail.com>
98+
UtkershBasnet <119008923+UtkershBasnet@users.noreply.github.com>
9799
Vaibhav Patel <98279986+noobCoderVP@users.noreply.github.com>
98100
Varad Gupta <varadgupta21@gmail.com>
99101
Xiaochuan Ye <tap91624@gmail.com>

docs/types/index.d.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,57 @@
4747
* var out = bar( 1, 2, 3 );
4848
* // returns [ 2, 4, 6 ]
4949
*/
50-
declare function mapArguments( fcn: Function, clbk: Function, thisArg?: any ): Function;
50+
declare function mapArguments<
51+
T extends ( ...args: Array<any> ) => any,
52+
C extends ( this: ThisParameterType<T>, value: Parameters<T>[number], index: number ) => any
53+
>(
54+
fcn: T,
55+
clbk: C
56+
): ( ...args: Parameters<T> ) => ReturnType<T>;
57+
58+
/**
59+
* Returns a function that applies arguments to a provided function after transforming arguments according to a callback function.
60+
*
61+
* ## Notes
62+
*
63+
* - The callback function is provided the following arguments:
64+
*
65+
* - **value**: argument value.
66+
* - **index**: argument index.
67+
*
68+
* @param fcn - input function
69+
* @param clbk - callback function
70+
* @param thisArg - input function context
71+
* @returns function wrapper
72+
*
73+
* @example
74+
* function foo( a, b, c ) {
75+
* return [ a, b, c ];
76+
* }
77+
*
78+
* function clbk( v ) {
79+
* this.count += 1;
80+
* return v * 2;
81+
* }
82+
*
83+
* var thisArg = { 'count': 0 };
84+
* var bar = mapArguments( foo, clbk, thisArg );
85+
*
86+
* var out = bar( 1, 2, 3 );
87+
* // returns [ 2, 4, 6 ]
88+
*
89+
* var count = thisArg.count;
90+
* // returns 3
91+
*/
92+
declare function mapArguments<
93+
T extends ( ...args: Array<any> ) => any,
94+
C extends ( this: ThisParameterType<T>, value: Parameters<T>[number], index: number ) => any,
95+
ThisArg
96+
>(
97+
fcn: T,
98+
clbk: C,
99+
thisArg: ThisArg
100+
): ( this: ThisArg, ...args: Parameters<T> ) => ReturnType<T>;
51101

52102

53103
// EXPORTS //

docs/types/test.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,37 @@
1818

1919
import mapArguments = require( './index' );
2020

21-
/**
22-
* Callback function.
23-
*
24-
* @param v - argument
25-
* @returns result
26-
*/
27-
function clbk( v: any ): any {
21+
// FUNCTIONS //
22+
23+
function clbk<T>( v: T ): T {
2824
return v;
2925
}
3026

27+
function stringify( n: number ): string {
28+
return n.toString();
29+
}
30+
31+
function sum( ...numbers: Array<number> ): number {
32+
return numbers.reduce( ( a, b ) => a + b, 0 );
33+
}
34+
35+
function greet( this: { name: string }, greeting: string ): string {
36+
return `${greeting}, ${this.name}!`; // eslint-disable-line no-invalid-this
37+
}
38+
3139

3240
// TESTS //
3341

3442
// The function returns a function...
3543
{
36-
mapArguments( ( x: any, y: any, z: any ): Array<any> => [ x, y, z ], clbk ); // $ExpectType Function
37-
mapArguments( ( x: any, y: any, z: any ): Array<any> => [ x, y, z ], clbk, {} ); // $ExpectType Function
44+
mapArguments( ( x: number, y: number, z: number ): Array<number> => [ x, y, z ], clbk ); // $ExpectType (x: number, y: number, z: number) => number[]
45+
mapArguments( ( x: string, y: string, z: string ): Array<string> => [ x, y, z ], clbk, {} ); // $ExpectType (this: {}, x: string, y: string, z: string) => string[]
46+
mapArguments( ( x: number, y: number ): number => x + y, clbk ); // $ExpectType (x: number, y: number) => number
47+
48+
mapArguments( stringify, ( x: number ) => x * 2 ); // $ExpectType (n: number) => string
49+
mapArguments( sum, ( x: number ) => x * 2 ); // $ExpectType (...args: number[]) => number
50+
51+
mapArguments( greet, ( s: string ) => s.toUpperCase(), { 'name': 'World' } ); // $ExpectType (this: { name: string; }, greeting: string) => string
3852
}
3953

4054
// The compiler throws an error if the function is provided a first argument other than a function...

0 commit comments

Comments
 (0)