Includes in TypeScript

Example of Includes use

Tenth challenge is Includes

If you have a tuple and want to check if the specific value exists, this is a challenge for you.

Iteration over tuples

Similar what we discussed in Making object out of tuple, we can use Indexed Access Types to get all the elements from the tuple:

Get union from the tuple

Afterwards we make sure we have an element U in the union of all elements from the tuple:

Solution

The solution as always is available on Playground

typescripteasy

Let's chat and have fun 🧑‍💻👩‍💻

No more often than once a week I write 📄 about TypeScript 💪, video playback 📺 and frontend related topics. You can unsubscribe in any time ↘️