I really wanted to get a type-safe function from an i18n lib I was using so I found this in a forum I never heard of. Enjoy!
// From https://ostack.cn/qa/?qa=416461/
type Cons<H, T> = T extends readonly any[]
? ((h: H, ...t: T) => void) extends (...r: infer R) => void
? R
: never
: never;