Рассмотрим на примере работы с массивом.
Что значит array as const в TypeScript
1. длинна всегда одинаковая
2. контент всегда одинаковый
const COLORS = ['white', 'blue', 'red'];
COLORS.push('yellow');
const COLORS = ['white', 'blue', 'red'] as const;
COLORS.push('yellow');
Если мы напишем as const, то любая операция которая, могла изменить длину или содержимое, больше не работает. Мы сообщаем TypeScript, что массив больше не изменится.
#reactjs
#javascript
#typescript
#usestate
#useeffect
#frontend
Подписывайтесь на телеграмм, будем готовиться к собесам: https://t.me/it_tonylife
Подписывайтесь на boosty: https://boosty.to/maxfri
On this page of the site you can watch the video online AS CONST | array as const | Советы TypeScript with a duration of hours minute second in good quality, which was uploaded by the user Iaroslav Silkin | Front-end 26 February 2024, share the link with friends and acquaintances, this video has already been watched 696 times on youtube and it was liked by 49 viewers. Enjoy your viewing!