# I Can’t Believe This TS Feature Has No Documentation

## Метаданные

- **Канал:** Web Dev Simplified
- **YouTube:** https://www.youtube.com/watch?v=lUnZ-NsD9Ag
- **Дата:** 23.04.2026
- **Длительность:** 1:27
- **Просмотры:** 59,994

## Описание

🌎 Find Me Here:

My Blog: https://blog.webdevsimplified.com/
My Courses: https://courses.webdevsimplified.com/
Patreon: https://www.patreon.com/WebDevSimplified
Twitter: https://twitter.com/DevSimplified
Discord: https://discord.gg/7StTjnR
GitHub: https://github.com/WebDevSimplified
CodePen: https://codepen.io/WebDevSimplified


#Shorts

## Содержание

### [0:00](https://www.youtube.com/watch?v=lUnZ-NsD9Ag) Segment 1 (00:00 - 01:00)

The TypeScript documentation isn't great, but in this case, there's absolutely no documentation for this incredible feature. Take for example this function first. It's a generic function that takes in an array of elements and returns to me the first element. In our case, we're passing an array of 1 2 and three. So, I would expect the return type of this to be either the value of 1 2 or 3 cuz that's the only things in my array. But if I hover over this num, you can see it actually has a return type of number instead of 1 2 or three. In order to make sure I get the correct return type, I would need to pass as const onto the end of this, which essentially says that this is a constant readonly array. And that gives me a little bit of a stricter type. And now when I hover over my number, you can see I get 1 2 or three, just like I would expect by stricting this down to a more strict type. But what if I don't want to have to be forced to pass as const every single time I call this function? I just know I want to take the strictest type every time. This is where passing a const generic comes in handy. you can pass const before the name of any generic. And essentially what that does is it acts like you passed as const at the end of whatever thing you're passing into this function. So in our case, you can see our number is now 1 2 or 3. It automatically counts this as a constant variable and gives us that stricter typing. Now in this particular use case, it's not super important, but when you're doing more advanced TypeScript projects, this type of feature is incredibly important. And if you want to see a use case of a real world project where I use this, I will link a video down at the bottom of your screen that uses this const feature heavily inside of a project for very particular use cases.

---
*Источник: https://ekstraktznaniy.ru/video/49386*