I show the reason Distributive Conditional Type needs to be used for Union Type in this post.
If generic type T is passed as Union Type like string | number
, then array item will be Union Type as below.
![](https://kenanhancer.com/wp-content/uploads/2023/01/Screenshot-2023-01-02-at-10.25.22-1024x372.png)
If you need to iterate on each type in Union Type, then Distributive Conditional Type (with extends
keywod) needs to be used.
![](https://kenanhancer.com/wp-content/uploads/2023/01/Screenshot-2023-01-02-at-10.27.17-1024x314.png)
To avoid distributive behaviour in Distibutive Conditional Type, surround each side of extends
keyword with square brackets.
![](https://kenanhancer.com/wp-content/uploads/2023/01/Screenshot-2023-01-02-at-10.28.44-1024x289.png)