Append argument type into function type in TypeScript
23 May 2021
Today we discuss AppendArgument
I didn't have that example in production so not sure if it's practical at all.
Anyway let's try to solve it 🚀
Infer arguments of a function
We already solved ReturnType challenge:
Similarly we can define Parameters
(which exists out of the box in TypeScript):
Let's use them both to infer Parameters
and ReturnType
for Fn
and append another argument:
It's working just fine – https://tsplay.dev/WGnZvm 🔥
Saving the names of function arguments in TypeScript
But what I want to improve here is to have the same labels (names of arguments in the function signature) we had before. If we hover over any example, we will see the difference:
We can achieve it with adding [...args: Args]
instead [...Args]
:
That's it 💫: https://tsplay.dev/wgrb4W
Thank you for your time 🙏🏻
typescript