Skip to content

Commit

Permalink
[solution]: en/medium-append-argument.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaiklor committed Nov 26, 2022
1 parent 5fcd1c9 commit 5c5c4aa
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions en/medium-append-argument.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,11 @@ type AppendArgument<Fn, A> = Fn extends (...args: infer P) => infer R

Now, the condition in conditional type evaluates to true, hence going into
“true” branch with a type parameter `P` (function parameters) and type parameter
`R` (return type). Although, we still have a problem. Type parameter `P` has a
tuple with function parameters, but we need to treat them as a separate
parameters.

By applying variadic tuple types, we can spread the tuple:
`R` (return type). Type parameter `P` has what we need now. The only thing left
is to construct our own new function signature from inferred types:

```ts
type AppendArgument<Fn, A> = Fn extends (...args: [...infer P]) => infer R
? (args: P) => R
: never;
```

Type parameter `P` has what we need now. The only thing left is to construct our
own new function signature from inferred types:

```ts
type AppendArgument<Fn, A> = Fn extends (...args: [...infer P]) => infer R
type AppendArgument<Fn, A> = Fn extends (...args: infer P) => infer R
? (...args: [...P]) => R
: never;
```
Expand All @@ -78,7 +66,7 @@ inferred types. Having that we can add the required `A` parameter to the
parameters list now:

```ts
type AppendArgument<Fn, A> = Fn extends (...args: [...infer P]) => infer R
type AppendArgument<Fn, A> = Fn extends (...args: infer P) => infer R
? (...args: [...P, A]) => R
: never;
```
Expand Down

0 comments on commit 5c5c4aa

Please sign in to comment.