Skip to content

Commit 77d628b

Browse files
committed
fix(pull): enhance pull function type definition
1 parent 1670983 commit 77d628b

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

docs/ja/reference/array/pull.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
## インターフェース
99

1010
```typescript
11-
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
11+
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
1212
```
1313

1414
### パラメータ

docs/ko/reference/array/pull.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
## 인터페이스
99

1010
```typescript
11-
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
11+
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
1212
```
1313

1414
### 파라미터
1515

1616
- `arr` (`T[]`): 수정할 배열.
17-
- `valuesToRemove` (`unknown[]`): 배열에서 제거할 값들.
17+
- `valuesToRemove` (`T[]`): 배열에서 제거할 값들.
1818

1919
### 반환 값
2020

docs/reference/array/pull.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ If you want to remove values without modifying the original array, use [differen
88
## Signature
99

1010
```typescript
11-
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
11+
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
1212
```
1313

1414
### Parameters
1515

1616
- `arr` (`T[]`): The array to modify.
17-
- `valuesToRemove` (`unknown[]`): The values to remove from the array.
17+
- `valuesToRemove` (`T[]`): The values to remove from the array.
1818

1919
### Returns
2020

docs/zh_hans/reference/array/pull.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
## 签名
99

1010
```typescript
11-
function pull<T>(arr: T[], valuesToRemove: unknown[]): T[];
11+
function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[];
1212
```
1313

1414
### 参数
1515

1616
- `arr` (`T[]`): 要修改的数组。
17-
- `valuesToRemove` (`unknown[]`): 要从数组中移除的值。
17+
- `valuesToRemove` (`T[]`): 要从数组中移除的值。
1818

1919
### 返回值
2020

src/array/pull.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
* This function changes `arr` in place.
55
* If you want to remove values without modifying the original array, use `difference`.
66
*
7-
* @template T, U
7+
* @template T - The type of elements in the array.
8+
* @template U - The type of values to remove from the array.
89
* @param {T[]} arr - The array to modify.
9-
* @param {unknown[]} valuesToRemove - The values to remove from the array.
10+
* @param {U[]} valuesToRemove - The values to remove from the array.
1011
* @returns {T[]} The modified array with the specified values removed.
1112
*
1213
* @example
1314
* const numbers = [1, 2, 3, 4, 5, 2, 4];
1415
* pull(numbers, [2, 4]);
1516
* console.log(numbers); // [1, 3, 5]
1617
*/
17-
export function pull<T>(arr: T[], valuesToRemove: readonly unknown[]): T[] {
18+
export function pull<T, U extends T>(arr: T[], valuesToRemove: readonly U[]): T[] {
1819
const valuesSet = new Set(valuesToRemove);
1920
let resultIndex = 0;
2021

2122
for (let i = 0; i < arr.length; i++) {
22-
if (valuesSet.has(arr[i])) {
23+
if (valuesSet.has(arr[i] as U)) {
2324
continue;
2425
}
2526

src/compat/array/pull.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import { pull as pullToolkit } from '../../array/pull.ts';
55
*
66
* **Note:** Unlike `_.without`, this method mutates `array`.
77
*
8-
* @template T
8+
* @template T - The type of elements in the array.
9+
* @template U - The type of values to remove from the array.
910
* @param {T[]} array - The array to modify.
10-
* @param {...T[]} values - The values to remove.
11+
* @param {...U[]} values - The values to remove.
1112
* @returns {T[]} Returns `array`.
1213
*
1314
* @example
@@ -17,14 +18,14 @@ import { pull as pullToolkit } from '../../array/pull.ts';
1718
* console.log(array);
1819
* // => [1, 1]
1920
*/
20-
export function pull<T>(array: T[], ...values: T[]): T[];
21+
export function pull<T, U extends T>(array: T[], ...values: U[]): T[];
2122

2223
/**
2324
* Removes all provided values from array using SameValueZero for equality comparisons.
2425
*
2526
* **Note:** Unlike `_.without`, this method mutates `array`.
2627
*
27-
* @template L
28+
* @template L - The type of elements in the array-like object.
2829
* @param {L} array - The array to modify.
2930
* @param {...L[0][]} values - The values to remove.
3031
* @returns {L} Returns `array`.
@@ -44,16 +45,17 @@ export function pull<L extends ArrayLike<any>>(array: L extends readonly any[] ?
4445
* This function changes `arr` in place.
4546
* If you want to remove values without modifying the original array, use `difference`.
4647
*
47-
* @template T, U
48+
* @template T - The type of elements in the array.
49+
* @template U - The type of values to remove from the array.
4850
* @param {T[]} arr - The array to modify.
49-
* @param {...unknown[]} valuesToRemove - The values to remove from the array.
51+
* @param {U[]} valuesToRemove - The values to remove from the array.
5052
* @returns {T[]} The modified array with the specified values removed.
5153
*
5254
* @example
5355
* const numbers = [1, 2, 3, 4, 5, 2, 4];
5456
* pull(numbers, [2, 4]);
5557
* console.log(numbers); // [1, 3, 5]
5658
*/
57-
export function pull<T>(arr: T[], ...valuesToRemove: readonly unknown[]): T[] {
59+
export function pull<T, U extends T>(arr: T[], ...valuesToRemove: readonly U[]): T[] {
5860
return pullToolkit(arr, valuesToRemove);
5961
}

0 commit comments

Comments
 (0)