Skip to content

Instantly share code, notes, and snippets.

View bdsqqq's full-sized avatar
🎨

Igor Bedesqui bdsqqq

🎨
View GitHub Profile
@bdsqqq
bdsqqq / NestedKeyOf.md
Created February 9, 2022 22:48
A way to get deeply nested types like if you were using `keyof`, it supports full blown path threes and just leaves too.

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;