Back to Type Challenges

README

questions/01097-medium-isunion/README.md

latest2.1 KB
Original Source
<!--info-header-start--><h1>IsUnion </h1><blockquote><p>by null <a href="https://github.com/bencor" target="_blank">@bencor</a></p></blockquote><p><a href="https://tsch.js.org/1097/play" target="_blank"></a> &nbsp;&nbsp;&nbsp;<a href="./README.ko.md" target="_blank"></a> </p><!--info-header-end-->

Implement a type IsUnion, which takes an input type T and returns whether T resolves to a union type.

For example:

ts
type case1 = IsUnion<string> // false
type case2 = IsUnion<string | number> // true
type case3 = IsUnion<[string | number]> // false
<!--info-footer-start-->

<a href="../../README.md" target="_blank"></a> <a href="https://tsch.js.org/1097/answer" target="_blank"></a> <a href="https://tsch.js.org/1097/solutions" target="_blank"></a> <hr><h3>Related Challenges</h3><a href="https://github.com/type-challenges/type-challenges/blob/main/questions/01042-medium-isnever/README.md" target="_blank"></a> <a href="https://github.com/type-challenges/type-challenges/blob/main/questions/00223-hard-isany/README.md" target="_blank"></a> <a href="https://github.com/type-challenges/type-challenges/blob/main/questions/04484-medium-istuple/README.md" target="_blank"></a> <!--info-footer-end-->