#Inferred second generic types parameter (???)

1 messages · Page 1 of 1 (latest)

cerulean lynx
#

I'm doing these exercises on this website and one of the solutions was this: https://typehero.dev/challenge/generic-function-arguments/solutions/89
it says it's a VERY detailed explanation, yet it doesn't really explain how the hell U is inferred. I also went on the TS handbook and there's nothing there. Can anybody help me out here? Is there some hidden part of the ts handbook where they explain this or am i stupid?

#

basically i don't understand how can it work if you not specify what the U type is

#

using a second generic would have to look like this:
<string, number>mapArray(...)

weary peak
#

U can be inferred because of the signature of parseInt
parseInt has signature (x: string) => number and the function passed to mapArray returns parseInt(str), so TS knows U is number

cerulean lynx
#

oh wait i think i get it now i think i was just being slow as always, thank you