Skip to content

Commit

Permalink
fix(partial): return type error (#832)
Browse files Browse the repository at this point in the history
* fix(partial): return type error

* fix
  • Loading branch information
D-Sketon authored Nov 29, 2024
1 parent 05261a9 commit eaabff5
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docs/ja/reference/function/partial.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Symbol型の`partial.placeholder`を使用すると、前もって提供した
## インターフェース

```typescript
function partial<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): F;
function partial<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partial {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partial {

### 戻り値

(`F`): 前もって引数が提供された関数。
(`(...args: any[]) => ReturnType<F>`): 前もって引数が提供された関数。

##

Expand Down
4 changes: 2 additions & 2 deletions docs/ja/reference/function/partialRight.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Symbol型の`partialRight.placeholder`を使用すると、事前に提供した
## インターフェース

```typescript
function partialRight<F extends (...args: any[] => any)>(func: F, ...partialArgs: any[]): F;
function partialRight<F extends (...args: any[] => any)>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partialRight {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partialRight {

### 戻り値

(`F`): 事前に引数が提供された関数。
(`(...args: any[]) => ReturnType<F>`): 事前に引数が提供された関数。

##

Expand Down
4 changes: 2 additions & 2 deletions docs/ko/reference/function/partial.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Symbol 타입의 `partial.placeholder`를 쓰면, 미리 제공한 인자가 사
## 인터페이스

```typescript
function partial<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): F;
function partial<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partial {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partial {

### 반환 값

(`F`): 미리 인자가 제공된 함수.
(`(...args: any[]) => ReturnType<F>`): 미리 인자가 제공된 함수.

## 예시

Expand Down
4 changes: 2 additions & 2 deletions docs/ko/reference/function/partialRight.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Symbol 타입의 `partialRight.placeholder`를 쓰면, 미리 제공한 인자
## 인터페이스

```typescript
function partialRight<F extends (...args: any[] => any)>(func: F, ...partialArgs: any[]): F;
function partialRight<F extends (...args: any[] => any)>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partialRight {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partialRight {

### 반환 값

(`F`): 미리 인자가 제공된 함수.
(`(...args: any[]) => ReturnType<F>`): 미리 인자가 제공된 함수.

## 예시

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/function/partial.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Note: This method doesn't set the `length` property of partially applied functio
## Signature

```typescript
function partial<F extends Function>(func: F, ...partialArgs: any[]): F;
function partial<F extends Function>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partial {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partial {

### Returns

(`F`): Returns the new partially applied function.
(`(...args: any[]) => ReturnType<F>`): Returns the new partially applied function.

## Examples

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/function/partialRight.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Note: This method doesn't set the `length` property of partially applied functio
## Signature

```typescript
function partialRight<F extends Function>(func: F, ...partialArgs: any[]): F;
function partialRight<F extends Function>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partialRight {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partialRight {

### Returns

(`F`): Returns the new partially applied function.
(`(...args: any[]) => ReturnType<F>`): Returns the new partially applied function.

## Examples

Expand Down
4 changes: 2 additions & 2 deletions docs/zh_hans/reference/function/partial.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## 签名

```typescript
function partial<F extends Function>(func: F, ...partialArgs: any[]): F;
function partial<F extends Function>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partial {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partial {

### 返回值

(`F`): 返回新的部分应用函数。
(`(...args: any[]) => ReturnType<F>`): 返回新的部分应用函数。

## 示例

Expand Down
4 changes: 2 additions & 2 deletions docs/zh_hans/reference/function/partialRight.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## 签名

```typescript
function partialRight<F extends Function>(func: F, ...partialArgs: any[]): F;
function partialRight<F extends Function>(func: F, ...partialArgs: any[]): (...args: any[]) => ReturnType<F>;

namespace partialRight {
placeholder: symbol;
Expand All @@ -25,7 +25,7 @@ namespace partialRight {

### 返回值

(`F`): 返回新的部分应用函数。
(`(...args: any[]) => ReturnType<F>`): 返回新的部分应用函数。

## 示例

Expand Down
4 changes: 0 additions & 4 deletions src/compat/util/iteratee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,9 @@ describe('iteratee', () => {
const expected = [1, 2, 3];
const object = { a: 1, iteratee: iteratee(partial(fn, 2)) };

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(object.iteratee(3)).toEqual(expected);

object.iteratee = iteratee(partialRight(fn, 3));
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
expect(object.iteratee(2)).toEqual(expected);
});

Expand Down
4 changes: 2 additions & 2 deletions src/function/partial.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('partial', () => {
});

it('partial creates a function that can be invoked with additional arguments', () => {
const fn = function (a?: string, b?: string) {
const fn = function (a: string, b: string) {
return [a, b];
};
const par = partial(fn, 'a');
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('partial', () => {
});

it('partial clones metadata for created functions', () => {
function greet(greeting?: string, name?: string) {
function greet(greeting: string, name: string) {
return `${greeting} ${name}`;
}

Expand Down
7 changes: 5 additions & 2 deletions src/function/partial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @template F The type of the function to partially apply.
* @param {F} func The function to partially apply arguments to.
* @param {any[]} partialArgs The arguments to be partially applied.
* @returns {F} Returns the new partially applied function.
* @returns {(...args: any[]) => ReturnType<F>} Returns the new partially applied function.
*
* @example
* function greet(greeting, name) {
Expand All @@ -24,7 +24,10 @@
* greetFred('hi');
* // => 'hi fred'
*/
export function partial<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): F {
export function partial<F extends (...args: any[]) => any>(
func: F,
...partialArgs: any[]
): (...args: any[]) => ReturnType<F> {
return function (this: any, ...providedArgs: any[]) {
const args: any[] = [];

Expand Down
4 changes: 2 additions & 2 deletions src/function/partialRight.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('partialRight', () => {
});

it('partialRight creates a function that can be invoked with additional arguments', () => {
const fn = function (a?: string, b?: string) {
const fn = function (a: string, b: string) {
return [a, b];
};
const par = partialRight(fn, 'a');
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('partialRight', () => {
});

it('partialRight clones metadata for created functions', () => {
function greet(greeting?: string, name?: string) {
function greet(greeting: string, name: string) {
return `${greeting} ${name}`;
}

Expand Down
7 changes: 5 additions & 2 deletions src/function/partialRight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @template F The type of the function to partially apply.
* @param {F} func The function to partially apply arguments to.
* @param {any[]} partialArgs The arguments to be partially applied.
* @returns {F} Returns the new partially applied function.
* @returns {(...args: any[]) => ReturnType<F>} Returns the new partially applied function.
*
* @example
* function greet(greeting, name) {
Expand All @@ -24,7 +24,10 @@
* sayHelloTo('fred');
* // => 'hello fred'
*/
export function partialRight<F extends (...args: any[]) => any>(func: F, ...partialArgs: any[]): F {
export function partialRight<F extends (...args: any[]) => any>(
func: F,
...partialArgs: any[]
): (...args: any[]) => ReturnType<F> {
return function (this: any, ...providedArgs: any[]) {
const placeholderLength = partialArgs.filter(arg => arg === partialRightPlaceholder).length;
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
Expand Down

0 comments on commit eaabff5

Please sign in to comment.