Back to Type Challenges

README

questions/32427-hard-unbox/README.md

latest1.7 KB
Original Source
<!--info-header-start--><h1>Unbox </h1><blockquote><p>by Julian Coy <a href="https://github.com/eXamadeus" target="_blank">@eXamadeus</a></p></blockquote><p><a href="https://tsch.js.org/32427/play" target="_blank"></a> </p><!--info-header-end-->

How can we build a type that "unboxes" arrays, functions, promises, and tuples?

Example:

typescript
Unbox<string> // string
Unbox<()=>number> // number
Unbox<boolean[]> // boolean
Unbox<Promise<boolean>> // boolean

Bonus: Can we make it recursive?

typescript
Unbox<() => () => () => () => number> // number

Double Bonus: Can we control the recursion?

typescript
Unbox<() => () => () => () => number, 3> // () => number
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/32427/answer" target="_blank"></a> <a href="https://tsch.js.org/32427/solutions" target="_blank"></a> <!--info-footer-end-->