{"id":459609,"date":"2025-05-14T09:17:20","date_gmt":"2025-05-14T09:17:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=459609"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=459609","title":{"rendered":"<span>\u041f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f TypeScript \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg 781w\" loading=\"lazy\" decode=\"async\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u0420\u0430\u043d\u0435\u0435 \u043d\u0430 Piccalilli \u0421\u044d\u043c \u0420\u043e\u0443\u0437 <a href=\"https:\/\/piccalil.li\/blog\/real-world-uses-of-typescripts-utility-types\/\">\u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 (utility types) TypeScript<\/a>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0438 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 TypeScript \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0438\u043f\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p> <\/p>\n<p>\u0426\u0435\u043b\u044c \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u0434\u0430\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p><a name=\"habracut\"><\/a> <\/p>\n<p>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c\u0443 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0443, \u044f \u0445\u043e\u0447\u0443 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u0437\u0430\u0447\u0435\u043c \u0432\u043e\u043e\u0431\u0449\u0435 \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u044d\u0442\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434 \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438.<\/p>\n<p> <\/p>\n<h2 id=\"-nemnogo-poleznoy-teorii\">\u276f \u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u0442\u0435\u043e\u0440\u0438\u0438<\/h2>\n<p> <\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0442\u0438\u043f\u044b \u0432 TypeScript \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u0430\u043a \u043d\u0435\u043a\u0438\u0435 &#171;\u0443\u043a\u0440\u0430\u0448\u0435\u043d\u0438\u044f&#187; \u0438\u043b\u0438 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u043d\u0430\u0434 \u043e\u0431\u044b\u0447\u043d\u044b\u043c JS-\u043a\u043e\u0434\u043e\u043c. \u0418 \u044f \u043d\u0435 \u0441\u0442\u0430\u043d\u0443 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u044c \u2014 \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u043d\u043e\u0433\u043e\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c! \u041e\u0434\u043d\u0430\u043a\u043e \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0430\u044f \u0441\u0438\u043b\u0430 \u0438 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c TypeScript \u0440\u0430\u0441\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0438\u043f\u044b \u043a\u0430\u043a \u043d\u0435\u043e\u0442\u044a\u0435\u043c\u043b\u0435\u043c\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p> <\/p>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u0433\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0435\u043d\u0438\u044f, \u043c\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0442\u0430\u043a \u0438\u043b\u0438 \u0438\u043d\u0430\u0447\u0435 \u0441\u0442\u0440\u043e\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u043b\u0438 \u043e\u0442\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0438\u0440\u0430 \u2014 \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e \u0438\u043b\u0438 \u043d\u0435\u0442. \u0422\u0438\u043f\u044b \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0444\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430. \u041a\u043b\u0430\u0441\u0441\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435, \u0430 \u0442\u0438\u043f\u044b \u2014 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0434\u0432\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043e\u0434\u043d\u043e\u0439 \u043c\u0435\u0434\u0430\u043b\u0438.<\/p>\n<p> <\/p>\n<p>\u0412 CSS \u043c\u044b <em>\u0432\u044b\u043d\u043e\u0441\u0438\u043c<\/em> \u043e\u0431\u0449\u0438\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u0438\u0437\u0430\u0439\u043d\u0430 \u0432 \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0435\u0434\u0438\u043d\u0438\u0446\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441\u044b) \u0438 <em>\u0441\u043e\u0447\u0435\u0442\u0430\u0435\u043c<\/em> \u0438\u0445 \u0434\u0440\u0443\u0433 \u0441 \u0434\u0440\u0443\u0433\u043e\u043c \u0447\u0435\u0440\u0435\u0437 \u043a\u0430\u0441\u043a\u0430\u0434. \u0422\u0430\u043a\u0438\u0435 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0438 \u0438 \u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u043a\u043e\u0434 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u043c \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c. \u0421 \u0442\u0438\u043f\u0430\u043c\u0438 \u0432\u0441\u0435 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435: \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 TypeScript \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u043e\u0431\u0449\u0438\u0435 \u0447\u0435\u0440\u0442\u044b \u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.<\/p>\n<p> <\/p>\n<p>\u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438 Flexbox, \u0438 Grid, \u043d\u043e <a href=\"https:\/\/piccalil.li\/blog\/if-it-works-its-right\/\">\u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/a>. \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f \u0438 \u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0442\u0438\u043f\u043e\u0432: \u043d\u0443\u0436\u043d\u043e \u043e\u0441\u043e\u0437\u043d\u0430\u043d\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c, \u043a\u0430\u043a\u0443\u044e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0440\u0430\u0434\u0438 \u043d\u0443\u0436\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u0444\u0430\u043a\u0442 <em>\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u044f<\/em> \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0432 \u044f\u0437\u044b\u043a\u0435 \u043d\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 <em>\u0441\u043b\u0435\u0434\u0443\u0435\u0442<\/em> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u042d\u0442\u043e \u0432 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u043c\u043e\u0449\u043d\u044b\u043c (\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c) \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0435\u0433\u043e\u0434\u043d\u044f.<\/p>\n<p> <\/p>\n<h2 id=\"-prakticheskiy-primer\">\u276f \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440<\/h2>\n<p> <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 \u0434\u043b\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0437\u0430 \u0434\u043e\u043c\u043e\u043c (\u0430-\u043b\u044f \u0443\u043c\u043d\u044b\u0439 \u0434\u043e\u043c) \u0438 \u0445\u043e\u0442\u0438\u043c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u043e\u0433\u0434\u0430 \u0434\u043e\u043c\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0442\u043e-\u0442\u043e \u0432\u0430\u0436\u043d\u043e\u0435 \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0434\u0432\u0435\u0440\u044c \u0438\u043b\u0438 \u0434\u0430\u0442\u0447\u0438\u043a \u0432\u043b\u0430\u0433\u0438 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u043e\u0434\u0443.<\/p>\n<p> <\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u0443 \u043d\u0430\u0441 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type EventName =   | 'open'   | 'close'   | 'locked'   | 'unlocked'   | 'moisture'   | 'motion';  type Access = {     sensorId: string;     \/\/ \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0434\u0432\u0435\u0440\u044c \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u043f\u0430\u043d\u0435\u043b\u0438,     \/\/ \u0438 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0439 \u043b\u0438\u0447\u043d\u044b\u0439 \u043a\u043e\u0434.     openedBy: string;     \/\/ \u0412\u0440\u0435\u043c\u044f \u0432 \u043c\u0438\u043b\u043b\u0438\u0441\u0435\u043a\u0443\u043d\u0434\u0430\u0445 \u0441 \u043d\u0430\u0447\u0430\u043b\u0430 \u044d\u043f\u043e\u0445\u0438 Unix.     \/\/ \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442,     \/\/ \u043d\u043e \u0442\u0430\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439.     timestamp: number; };  type Moisture = {     sensorId: string;     timestamp: number; };  type Motion = {     cameraId: string;     timestamp: number; };  const sendEvent = (     event: EventName,     payload: Access | Moisture | Motion ) =&gt; { \/* ... *\/ };<\/code><\/pre>\n<p> <\/p>\n<p>\u0422\u0438\u043f <code>EventName<\/code> \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>Access<\/code>, <code>Moisture<\/code> \u0438 <code>Motion<\/code> \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 <em>\u0434\u0430\u043d\u043d\u044b\u0435<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435\u043c. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u044d\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043d\u0435 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439 (payload)!<\/p>\n<p> <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438 \u0434\u0430\u043d\u043d\u044b\u0435, \u0432\u0432\u0435\u0434\u044f \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type HomeEvents = {   open: Access;   close: Access;   locked: Access;   unlocked: Access;   moisture: Moisture;   motion: Motion; };<\/code><\/pre>\n<p> <\/p>\n<p>\u041a\u043b\u044e\u0447\u0438 \u0442\u0438\u043f\u0430 <code>HomeEvents<\/code> \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u0443\u044e \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u044d\u0442\u0438\u0445 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p> <\/p>\n<p>\u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 <code>HomeEvents<\/code> \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043f\u043e\u043b\u0435\u0437\u0435\u043d, \u043d\u043e \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/indexed-access-types.html\">\u0442\u0438\u043f\u0430\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443\/\u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/a>(indexed access types) \u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044c\u0441\u044f \u0432\u043f\u0435\u0440\u0435\u0434!<\/p>\n<p> <\/p>\n<p><em>\u0418\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/em> \u2014 \u044d\u0442\u043e \u0442\u0438\u043f\u043e\u0432\u043e\u0439 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u043e\u0431\u044b\u0447\u043d\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u0432 JS:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type Company = {   name: String;   revenue: number; }  const edison: Company = {     name: \"Edison Power Co\",     revenue: 9001 };  const r = edison['revenue']; \/\/ 9001 type Revenue = Company['revenue']; \/\/ number<\/code><\/pre>\n<p> <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430\u044f \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0432 JS, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0441 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u043c\u0438 \u0441\u043a\u043e\u0431\u043a\u0430\u043c\u0438 <code>[]<\/code>. \u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 <em>\u0442\u0438\u043f\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/em> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0443 \u0436\u0435 \u043d\u043e\u0442\u0430\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <em>\u0442\u0438\u043f<\/em> \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u043c\u044b \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438, \u0442\u0430\u043a\u0438\u043c\u0438 \u043a\u0430\u043a <code>revenue<\/code>. \u0412 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043a\u0430\u0445 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u0442\u0438\u043f\u044b:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">Company['name' | 'revenue'] \/\/ string | number<\/code><\/pre>\n<p> <\/p>\n<p>\u0421 \u044d\u0442\u0438\u043c \u043d\u043e\u0432\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type Access = {     sensorId: string;     openedBy: string;     timestamp: number; };  type Moisture = {     sensorId: string;     timestamp: number; };  type Motion = {     cameraId: string;     timestamp: number; };  type HomeEvents = {   open: Access;   close: Access;   locked: Access;   unlocked: Access;   moisture: Moisture;   motion: Motion; };  const sendEvent = (     event: string,     payload: HomeEvents[string] ) =&gt; { \/* ... *\/ };<\/code><\/pre>\n<p> <\/p>\n<p>\u041d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443: <code>Type 'HomeEvents' has no matching index signature for type 'string'.(2537)<\/code>. \u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, <code>HomeEvents<\/code> \u043d\u0435\u043b\u044c\u0437\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043b\u044e\u0431\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c. \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0434\u043b\u044f <code>event<\/code>. \u041e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u2014 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0442\u0438\u043f <code>EventName<\/code>:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type EventName =   | 'open'   | 'close'   | 'locked'   | 'unlocked'   | 'moisture'   | 'motion';  type HomeEvents = {   open: Access;   close: Access;   locked: Access;   unlocked: Access;   moisture: Moisture;   motion: Motion; };  const sendEvent = (     event: EventName,     \/\/ HomeEvents[string] -&gt; HomeEvents[EventName]     payload: HomeEvents[EventName] ) =&gt; { \/* ... *\/ };<\/code><\/pre>\n<p> <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f, \u043d\u043e \u0432\u0441\u0435 \u0435\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b:<\/p>\n<p> <\/p>\n<ol>\n<li>\u041c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u0432\u0430\u0436\u0434\u044b.<\/li>\n<li>\u0422\u0438\u043f\u044b <code>event<\/code> \u0438 <code>payload<\/code> \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439.<\/li>\n<\/ol>\n<p> <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0435\u0440\u0432\u0443\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u2014 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>keyof<\/code>. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>keyof<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0442\u0438\u043f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0439:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type Bird = {     species: string;     color: string;     age: number; };  \/\/ \u042d\u0442\u0438 \u0434\u0432\u0430 \u0442\u0438\u043f\u0430 \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442\u043d\u044b type BirdProperties  = keyof Bird; type _BirdProperties = 'species' | 'color' | 'age'<\/code><\/pre>\n<p> <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u0443\u0441\u0442\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0442\u0438\u043f\u0430\u043c\u0438 <code>EventName<\/code> \u0438 <code>HomeEvents<\/code>, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u044c <code>EventName<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0438\u0437 <code>HomeEvents<\/code> \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>keyof<\/code>:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type HomeEvents = {   open: Access;   close: Access;   locked: Access;   unlocked: Access;   moisture: Moisture;   motion: Motion; };  type EventName = keyof HomeEvents;  const sendEvent = (     event: EventName,     payload: HomeEvents[EventName] ) =&gt; { \/* ... *\/ };<\/code><\/pre>\n<p> <\/p>\n<p>\u042d\u0442\u043e \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u0435\u0442 \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u2014 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0442\u0438\u043f\u043e\u0432 \u043d\u0435\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u043b \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438 \u0438\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>sendEvent<\/code> \u0441 \u0441\u043e\u0431\u044b\u0442\u0438\u0435\u043c <code>\"motion\"<\/code>, \u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f <code>Access<\/code>!<\/p>\n<p> <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u0431\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 (generic types). \u042d\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u0430 \u0437\u0430\u0442\u0435\u043c \u043e\u0431\u044a\u044f\u0441\u043d\u044e \u0435\u0433\u043e \u0448\u0430\u0433 \u0437\u0430 \u0448\u0430\u0433\u043e\u043c:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/* const sendEvent = (     event: EventName,     payload: HomeEvents[EventName] ) =&gt; {}; *\/  const sendEvent = &lt;E extends EventName,&gt;(     event: E,     payload: HomeEvents[E] ) =&gt; { \/* ... *\/ };<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"zavershayuschaya-zapyataya\">\u0417\u0430\u0432\u0435\u0440\u0448\u0430\u044e\u0449\u0430\u044f \u0437\u0430\u043f\u044f\u0442\u0430\u044f<\/h3>\n<p> <\/p>\n<p>\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 JSX \u0438 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html\">\u043e\u0431\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432<\/a> \u0432 TypeScript \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0437\u0430\u043f\u044f\u0442\u0430\u044f \u0432 \u043a\u043e\u043d\u0446\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043f\u0430\u0440\u0441\u0435\u0440\u0443 \u0438 \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0435 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043e\u0431\u0449\u0438\u0439 \u0442\u0438\u043f, \u0430 \u043d\u0435 JSX-\u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<p> <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u0432\u0430\u043c \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u044b\u043c, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">function sendEvent&lt;E extends EventName&gt;(     event: E,     payload: HomeEvents[E] ) { \/* *\/ }<\/code><\/pre>\n<p> <\/p>\n<p>\u0412 \u0438\u0442\u043e\u0433\u043e\u0432\u043e\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u043c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0442\u0438\u043f\u0430 <code>E<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>sendEvent<\/code>. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u2014 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p> <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044e \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u043b\u0430 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440: <code>const sum = 2 + 2<\/code>. \u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0432\u0432\u043e\u0434\u0438\u043c \u0438\u043c\u0435\u043d\u0430 \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u044d\u0442\u0438\u043c\u0438 \u0438\u043c\u0435\u043d\u0430\u043c\u0438, \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0447\u0438\u0441\u043b\u0430\u0445, \u0442\u043e \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e: <code>const add = (x, y) =&gt; x + y;<\/code>.<\/p>\n<p> <\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>x<\/code> \u0438 <code>y<\/code> \u0432 \u044d\u0442\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014 \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html\">&#171;\u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438&#187;<\/a> \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u044b \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435. \u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0438 \u0441 \u043e\u0431\u0449\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438: \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 &#171;\u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c&#187; (placeholder) \u0434\u043b\u044f <em>\u0442\u0438\u043f\u0430<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u043e\u0437\u0436\u0435, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p> <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u043b\u0438\u0448\u044c \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0442\u0438\u043f\u044b \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043b\u043e\u0433\u0438\u043a\u0438, \u043f\u043e\u043b\u044c\u0437\u044b \u043e\u0442 \u043d\u0438\u0445 \u0431\u044b\u043b\u043e \u0431\u044b \u043d\u0435\u043c\u043d\u043e\u0433\u043e. \u041a\u0430\u043a \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">const log = &lt;T,&gt;(x: T) {   console.log(x); }<\/code><\/pre>\n<p> <\/p>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>T<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c \u0442\u0438\u043f\u043e\u043c, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>x<\/code> \u043f\u043e \u0441\u0443\u0442\u0438 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435 \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c. \u0415\u0441\u043b\u0438 \u0431\u044b \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0432\u0441\u0435, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043e\u0431\u0449\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438, \u0438\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0431\u044b\u043b\u0430 \u0431\u044b \u043d\u0435\u0432\u0435\u043b\u0438\u043a\u0430. \u0412\u043e\u0442 \u0437\u0434\u0435\u0441\u044c \u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>extends<\/code>.<\/p>\n<p> <\/p>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>extends<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043b\u043e\u0436\u0438\u0442\u044c <em>\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f<\/em> \u043d\u0430 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0435\u0433\u043e \u0442\u0438\u043f\u0430 \u2014 \u0442\u0430\u043a\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 <em>\u0433\u0440\u0430\u043d\u0438\u0446\u0430\u043c\u0438 \u043e\u0431\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432<\/em> (generic type bounds). \u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u044e \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0442\u0430\u043a\u0438\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">const add = (x: number, y: number) =&gt; x + y;  \/\/ ---  type Pet {     name: string;     age: number; }  type Fish = Pet &amp; {     waterType: 'fresh' | 'salt'; };  type Cat = Pet &amp; {     cuteness: number; };  type Dog = Pet &amp; {     tailWagLevel: number; };  const feedPet = &lt;P extends Pet,&gt;(pet: P) =&gt; { \/* *\/ };<\/code><\/pre>\n<p> <\/p>\n<p><code>x<\/code> \u0438 <code>y<\/code> \u2014 \u044d\u0442\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u0438 \u0434\u043b\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043d\u043e \u0442\u0438\u043f <code>number<\/code>, <strong>\u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u043b\u0430.<\/strong><\/p>\n<p> <\/p>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f <code>P<\/code> \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>feedPet<\/code> \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d \u0442\u0438\u043f\u043e\u043c <code>Pet<\/code>, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442: \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043c\u0435\u043d\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 <code>Pet<\/code> \u0438\u043b\u0438 \u043b\u044e\u0431\u043e\u0439 \u0435\u0433\u043e \u043f\u043e\u0434\u0442\u0438\u043f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 <code>Cat<\/code> \u0438\u043b\u0438 <code>Dog<\/code>.<\/p>\n<p> <\/p>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 <code>extends<\/code> \u0432 TypeScript:<\/p>\n<p> <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0438\u043f <code>T<\/code> \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0442\u0438\u043f <code>U<\/code> (T extends U), \u0442\u043e <em>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/em> \u0442\u0438\u043f\u0430 <code>T<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0435\u0437\u0434\u0435, \u0433\u0434\u0435 \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>U<\/code>.<\/p>\n<p> <\/p>\n<h3 id=\"zvuchit-znakomo\">\u0417\u0432\u0443\u0447\u0438\u0442 \u0437\u043d\u0430\u043a\u043e\u043c\u043e?<\/h3>\n<p> <\/p>\n<p>\u0412\u044b, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u043e\u0431 \u044d\u0442\u043e\u043c \u043a\u0430\u043a \u043e <a href=\"https:\/\/ru.wikipedia.org\/wiki\/%D0%9F%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF_%D0%BF%D0%BE%D0%B4%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%BA%D0%B8_%D0%9B%D0%B8%D1%81%D0%BA%D0%BE%D0%B2\">\u041f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043f\u043e\u0434\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u041b\u0438\u0441\u043a\u043e\u0432<\/a> (Liskov Substitution Principle, LSP).<\/p>\n<p> <\/p>\n<h2 id=\"-vozvraschaemsya-k-ishodnomu-primeru\">\u276f \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u0443<\/h2>\n<p> <\/p>\n<p>\u0427\u0442\u043e \u044d\u0442\u043e \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0438\u0442 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>sendEvent<\/code>? \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u0442\u0438\u043f <code>event<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043f\u043e\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0442\u0438\u043f\u0430 <code>EventName<\/code>.<\/p>\n<p> <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0442\u0438\u043f\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 const sendEvent = &lt;E extends EventName,&gt;(     event: E,     payload: HomeEvents[E] ) =&gt; { \/* ... *\/ };  \/\/ \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0438\u043c\u044f `event`, \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \/\/ \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u0438\u043f\u044b sendEvent('motion', \/* \u041a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u0437\u0434\u0435\u0441\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d? *\/);  \/\/ \u0428\u0430\u0433 1: const sendEvent = &lt;'motion' extends EventName,&gt;(     event: 'motion',     payload: HomeEvents['motion'] ) =&gt; { \/* ... *\/ };  \/\/ \u0428\u0430\u0433 2: const sendEvent = &lt;'motion' extends EventName,&gt;(     event: 'motion',     payload: Motion ) =&gt; { \/* ... *\/ };<\/code><\/pre>\n<p> <\/p>\n<p>\u041e\u0431\u0449\u0438\u0439 \u0442\u0438\u043f \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u0442\u0438\u043f <code>event<\/code> \u0438 \u0442\u0438\u043f <code>payload<\/code> \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0443\u0442\u0430\u0442\u044c \u0438\u043c\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0441 \u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439.<\/p>\n<p> <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>keyof<\/code>, \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0438 \u0442\u0438\u043f\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443 \u0432\u043c\u0435\u0441\u0442\u0435. \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u043f\u044b\u0442 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 TypeScript, \u0438\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/typescript-in-5-minutes-func.html#discriminated-unions\">\u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (discriminated unions)<\/a>, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0432\u0430\u043c \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u043f\u0440\u0438\u0434\u0443\u0442 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u043e\u0441\u043e\u0431\u044b \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>sendEvent<\/code>. \u0414\u0435\u0440\u0437\u0430\u0439\u0442\u0435 \ud83d\ude09<\/p>\n<p> <\/p>\n<h2 id=\"-otobrazhaemye-tipy\">\u276f \u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/h2>\n<p> <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c TypeScript \u2014 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/mapped-types.html\">\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b (mapped types)<\/a>.<\/p>\n<p> <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043e\u0431\u0441\u0443\u0436\u0434\u0435\u043d\u0438\u044f \u0441\u0430\u043c\u043e\u0439 \u0438\u0434\u0435\u0438 &#171;\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f&#187; \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438. \u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430\/\u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430, \u043a\u0430\u043a \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">const countingNumbers = [1,2,3,4,5]; const evens = countingNumbers.map(n =&gt; n * 2); console.log(evens); \/\/ [2,4,6,8,10]<\/code><\/pre>\n<p> <\/p>\n<p>\u042d\u0442\u0443 \u0438\u0434\u0435\u044e \u043b\u0435\u0433\u043a\u043e \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0435 \u0442\u0438\u043f\u044b, \u043f\u0440\u043e\u0445\u043e\u0434\u044f \u043f\u043e \u043f\u0430\u0440\u0430\u043c &#171;\u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435&#187; (\u0445\u043e\u0442\u044f \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u043d\u0430\u0434\u043e \u043f\u0440\u0438\u0437\u043d\u0430\u0442\u044c, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0439):<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">const grossRevenues = {   \"Edison Power Co.\": 5760,   \"Best Ever Kebabs\": 9756,   \"Tarjan &amp; Co. Networking Service\": 10755,   \"Ford Fulkerson Plumbing\": 42665 };  const applyTaxes = (     businessName: string,     revenue: number ) =&gt; [businessName, revenue - revenue * 0.20] as const;  const postTaxRevenue = Object.fromEntries(     Object.entries(grossRevenues).map(         ([key, value]) =&gt; applyTaxes(key, value)     ) );  \/* \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430: Object.entries(grossRevenues).reduce((acc, [k, v]) =&gt; {     const [newKey, newValue] = applyTaxes(k, v);     acc[newKey] = newValue;     return acc; }, {} as Record&lt;string, number&gt;); *\/<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"rol-as-const\">\u0420\u043e\u043b\u044c <code>as const<\/code><\/h3>\n<p> <\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 TypeScript \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043e\u0431\u0449\u0438\u0439 \u0442\u0438\u043f. \u0411\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>as const<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>applyTaxes<\/code> \u0431\u0443\u0434\u0435\u0442 <code>(string | number)[]<\/code>, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c, \u0442\u0430\u043a \u043a\u0430\u043a TypeScript \u0431\u0443\u0434\u0435\u0442 \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u0438\u043f\u043e\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>key<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>string | number<\/code>.<\/p>\n<p> <\/p>\n<p>\u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f \u0434\u043b\u044f <code>applyTaxes<\/code> \u2014 \u044d\u0442\u043e \u043a\u043e\u0440\u0442\u0435\u0436: <code>readonly [string, number]<\/code>, \u043d\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b TypeScript \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u044d\u0442\u043e\u0442 \u0442\u0438\u043f \u0432\u043c\u0435\u0441\u0442\u043e \u0431\u043e\u043b\u0435\u0435 \u043e\u0431\u0449\u0435\u0433\u043e <code>(string | number)[]<\/code>, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>as const<\/code>.<\/p>\n<p> <\/p>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044e \u0438 \u0435\u0435 \u0432\u0430\u043b\u043e\u0432\u044b\u0439 \u0434\u043e\u0445\u043e\u0434 \u0441 \u043d\u043e\u0432\u043e\u0439 \u043f\u0430\u0440\u043e\u0439 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u0435\u0435 \u0434\u043e\u0445\u043e\u0434 \u043f\u043e\u0441\u043b\u0435 \u0443\u043f\u043b\u0430\u0442\u044b \u043d\u0430\u043b\u043e\u0433\u043e\u0432. \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0438, \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0445 \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u0445 \u043a\u043b\u044e\u0447\u0435\u0439 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442.\u0434.<\/p>\n<p> <\/p>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f \u044d\u0442\u043e \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e, \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0447\u0442\u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0435, \u043d\u043e \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 <em>\u0442\u0438\u043f\u043e\u0432<\/em>.<\/p>\n<p> <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0437\u0430 \u0434\u043e\u043c\u043e\u043c, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0448\u043b\u0430 \u0440\u0435\u0447\u044c \u0440\u0430\u043d\u0435\u0435. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c <em>\u043d\u0430\u043b\u0438\u0447\u0438\u0435<\/em> \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0430\u0442\u0447\u0438\u043a\u0430. \u041d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u0432\u0435\u0441\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0440\u0430\u043d\u0435\u0435:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type HomeEvents = {   open: Access;   close: Access;   locked: Access;   unlocked: Access;   moisture: Moisture;   motion: Motion; };  \/\/ \u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f type HasSensors = {     [SensorName in keyof HomeEvents]: boolean; };<\/code><\/pre>\n<p> <\/p>\n<p>\u0422\u0438\u043f <code>HasSensors<\/code> \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u043e:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type HasSensors = {   open: boolean;   close: boolean;   locked: boolean;   unlocked: boolean;   moisture: boolean;   motion: boolean; }; \/\/ \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u043b\u044e\u0447\u0435\u0439, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \"close\", \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u043c\u044b\u0441\u043b\u0430 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0441\u0435\u043d\u0441\u043e\u0440\u043e\u0432. \/\/ \u041d\u043e \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/code><\/pre>\n<p> <\/p>\n<p>\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u044e\u0442 \u0442\u0438\u043f\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0445\u043e\u0434\u0441\u0442\u0432\u0430. \u041c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0441 \u0444\u0438\u0433\u0443\u0440\u043d\u044b\u0445 \u0441\u043a\u043e\u0431\u043e\u043a, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0438\u0448\u0435\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u0430\u0436\u0434\u0443\u044e \u043f\u0430\u0440\u0443 \u043a\u043b\u044e\u0447-\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435. &#171;\u0421\u0442\u043e\u0440\u043e\u043d\u0430 \u043a\u043b\u044e\u0447\u0430&#187; \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a <code>[KeyType in KeySourceType]<\/code>, \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u0430\u043a \u0446\u0438\u043a\u043b <code>for<\/code>:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">for (let i of [1,2,3]) {     console.log(i); }<\/code><\/pre>\n<p> <\/p>\n<p>\u0412 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u0441\u043d\u0438\u043f\u043f\u0435\u0442\u0435 <code>i<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0430: \u0441\u043d\u0430\u0447\u0430\u043b\u0430 <code>1<\/code>, \u043f\u043e\u0442\u043e\u043c <code>2<\/code> \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, <code>3<\/code>.<\/p>\n<p> <\/p>\n<p>\u0412 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u043c \u0442\u0438\u043f\u0435 <code>KeyType<\/code> \u2014 \u044d\u0442\u043e \u043a\u0430\u043a <code>i<\/code>, \u0430 <code>KeySourceType<\/code> \u2014 \u044d\u0442\u043e \u043a\u0430\u043a \u043c\u0430\u0441\u0441\u0438\u0432. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 <code>HasTypes<\/code>, <code>SensorName<\/code> \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0432\u0435\u043d <code>'open'<\/code>, \u0437\u0430\u0442\u0435\u043c <code>'close'<\/code> \u0438 \u0442.\u0434., \u043f\u043e\u043a\u0430 \u043d\u0435 \u043f\u0440\u0438\u043c\u0435\u0442 \u0432\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 <code>keyof HomeEvents<\/code>. \u041c\u044b \u043a\u0430\u043a \u0431\u044b &#171;\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c&#187; \u2014 \u0438\u043b\u0438, \u0433\u043e\u0432\u043e\u0440\u044f \u0438\u043d\u0430\u0447\u0435, \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u0432\u0441\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430\u043c \u0438\u0437 <code>KeySourceType<\/code>.<\/p>\n<p> <\/p>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 &#171;\u0441\u0442\u043e\u0440\u043e\u043d\u044b \u043a\u043b\u044e\u0447\u0430&#187; (\u0441\u043b\u0435\u0432\u0430 \u043e\u0442 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f) \u2014 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0438\u043c\u0435\u043d \u043a\u043b\u044e\u0447\u0435\u0439 \u0432 \u043d\u043e\u0432\u043e\u043c \u0442\u0438\u043f\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0417\u0430\u0434\u0430\u0447\u0430 &#171;\u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f&#187; (\u0441\u043f\u0440\u0430\u0432\u0430 \u043e\u0442 \u0434\u0432\u043e\u0435\u0442\u043e\u0447\u0438\u044f) \u2014 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p> <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0438\u0448\u0435\u043c:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type HasSensors = {     [SensorName in keyof HomeEvents]: boolean; };<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c TS: &#171;\u0421\u043e\u0437\u0434\u0430\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0442\u0438\u043f \u0438\u0437 \u043a\u043b\u044e\u0447\u0435\u0439 \u0442\u0438\u043f\u0430 <code>HomeEvents<\/code> \u0438 \u043d\u0430\u0437\u043d\u0430\u0447\u044c \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 \u0442\u0438\u043f <code>boolean<\/code>&#171;.<\/p>\n<p> <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c: &#171;\u042d\u0442\u043e \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e&#187;, \u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043c\u043e\u0433\u0443\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u044c\u0448\u0435. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c (\u0438 \u0447\u0430\u0441\u0442\u043e \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f) \u043e\u0431\u0449\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0442\u0438\u043f <code>HasSensors<\/code>, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441 \u043b\u044e\u0431\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type BooleanProperties&lt;Type&gt; = {     [Key in keyof Type]: boolean; };<\/code><\/pre>\n<p> <\/p>\n<p>\u0422\u0438\u043f <code>MakeBoolean<\/code> \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e <code>HasSensors<\/code>, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u043a \u043b\u044e\u0431\u043e\u043c\u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0443:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type DrawingTools = {     pencil: () =&gt; {};     fill: () =&gt; {};     pen: () =&gt; {}; };  type WhichToolsActive = BooleanProperties&lt;DrawingTools&gt;;  \/* \u0410\u043d\u0430\u043b\u043e\u0433: {     pencil: boolean;     fill: boolean;     pen: boolean; } *\/<\/code><\/pre>\n<p> <\/p>\n<p>\u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043b\u044e\u0447\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type EventGetters = {     \/\/ \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a     \/\/ \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0435\u043e\u0431\u044b\u0447\u043d\u043e. \u042f \u0434\u0435\u043b\u0430\u044e \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430     [         SensorName in         keyof HomeEvents         \/\/ \u041d\u043e\u0432\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441         as `get${Capitalize&lt;SensorName&gt;}Event`     ]: (eventId: string) =&gt; HomeEvents[SensorName] }  \/* \u041f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432: {     getOpenEvent: (eventId: string) =&gt; Access;     getCloseEvent: (eventId: string) =&gt; Access;     ...     getMoistureEvent: (eventId: string) =&gt; Motion; }<\/code><\/pre>\n<p> <\/p>\n<p>\u0427\u0430\u0441\u0442\u044c <code>as<\/code> \u043d\u0430 &#171;\u0441\u0442\u043e\u0440\u043e\u043d\u0435 \u043a\u043b\u044e\u0447\u0430&#187; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u044c <code>HomeEvents<\/code> \u0432 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">\/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e 3 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0442\u0438 \/\/ `propertyNames` \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d `keyof HomeEvents` const propertyNames = [\"open\", \"close\", \"moisture\"]; \/\/ `newPropertyNames` \u2014 \u044d\u0442\u043e \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \/\/ \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430. const newPropertyNames = propertyNames.map(     \/\/ \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0440\u043e\u043b\u044c `as`     (property) =&gt; `get${capitalize(property)}Event` );  \/\/ \u0423\u0442\u0438\u043b\u0438\u0442\u0430 `Capitalize` \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0432 TypeScript, \/\/ \u043d\u043e \u0434\u043b\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u0445 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u0432\u0440\u0443\u0447\u043d\u0443\u044e. const capitalize = (s: string): string =&gt; {     return s[0].toLocaleUpperCase() + s.slice(1); };<\/code><\/pre>\n<p> <\/p>\n<h3 id=\"kratkiy-obzor-modifikatorov-otobrazheniya\">\u041a\u0440\u0430\u0442\u043a\u0438\u0439 \u043e\u0431\u0437\u043e\u0440 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/h3>\n<p> <\/p>\n<p>\u042f \u0443\u043f\u043e\u043c\u044f\u043d\u0443 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432\u0441\u043a\u043e\u043b\u044c\u0437\u044c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b \u043c\u043e\u0433\u0443\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u0438\u0441\u0442\u0438\u043a\u0438, \u043a\u0430\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0441\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>readonly<\/code>) \u0438\u043b\u0438 \u0435\u0433\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>optional<\/code>), \u0447\u0435\u0440\u0435\u0437 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/mapped-types.html#mapping-modifiers\">&#171;\u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f&#187; (mapping modifiers)<\/a>. \u041e\u0441\u0442\u0430\u0432\u043b\u044e \u044d\u0442\u043e \u043a\u0430\u043a \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p> <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0432\u0441\u0435, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u2014 \u044d\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p> <\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type WithAuditor&lt;T&gt; = T &amp; {     auditorId: string;     auditedOn: Date; };  \/\/ \u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0445 \u044d\u0442\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0435\u0432\u0430\u0436\u043d\u044b. \/\/ \u0411\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0435 \u0442\u0438\u043f\u044b. type BusinessRecords = {     notesAnDisclosures: NotesAndDisclosures;     profitLoss: ProfitLoss;     retainedEarnings: RetainedEarnings; };  type ApplyAudit&lt;Type&gt; = {     [Key in keyof Type]: WithAuditor&lt;Type[Key]&gt;; }  type Audit = (records: BusinessRecords) =&gt; ApplyAudit&lt;BusinessRecords&gt;;<\/code><\/pre>\n<p> <\/p>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0445\u043e\u0442\u044f \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b (conditional types) \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u043e\u0442\u043c\u0435\u0447\u0443, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0441 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u043c\u0438 <em>\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e<\/em> \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438. &#171;\u0423\u0441\u043b\u043e\u0432\u043d\u044b\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0439 \u0442\u0438\u043f&#187; \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c \u0434\u043b\u044f \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a <code>DeepPartial<\/code> \u0438\u0437 <a href=\"https:\/\/piccalil.li\/blog\/real-world-uses-of-typescripts-utility-types\/\">\u0441\u0442\u0430\u0442\u044c\u0438 \u0421\u044d\u043c\u0430 \u0420\u043e\u0443\u0437\u0430 \u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445<\/a>) \u0438\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u044e\u0447\u0435\u0439 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u043e\u0432 <em>\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439<\/em>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p> <\/p>\n<pre><code class=\"javascript\">type ModalProps = {     show: boolean;     greeting: string;     onClose: () =&gt; void;     onOpen: () =&gt; void; };  \/\/ \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0442\u0438\u043f\u0430 type ModalFunctions = FunctionsOnly&lt;ModalProps&gt;;  \/* {   onClose: () =&gt; void;   onOpen: () =&gt; void; } *\/<\/code><\/pre>\n<p> <\/p>\n<h2 id=\"-zaklyuchenie\">\u276f \u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p> <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 <em>\u043c\u043d\u043e\u0433\u043e<\/em> \u0432\u0430\u0436\u043d\u044b\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0439:<\/p>\n<p> <\/p>\n<ol>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/indexed-access-types.html#handbook-content\">\u0422\u0438\u043f\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043f\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0443<\/a><\/li>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/keyof-types.html#handbook-content\"><code>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 keyof<\/code><\/a><\/li>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html\">\u041e\u0441\u043d\u043e\u0432\u044b \u043e\u0431\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432<\/a><\/li>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/generics.html#generic-constraints\"><code>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043e\u0431\u0449\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 extends<\/code><\/a><\/li>\n<li><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/mapped-types.html\">\u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0442\u0438\u043f\u044b<\/a><\/li>\n<\/ol>\n<p> <\/p>\n<p>\u042d\u0442\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u2014 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f <em>\u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445<\/em>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0433\u0440\u0430\u043c\u043e\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0431\u043e\u0440\u0430 \u0438 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0435, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0435 \u0438 \u0442\u043e\u0447\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p> <\/p>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u043a\u0430\u043a \u0438 \u043b\u044e\u0431\u0430\u044f \u043c\u043e\u0449\u043d\u0430\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u0447\u0440\u0435\u0437\u043c\u0435\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u0441 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043a\u043e\u0434\u0430. \u041f\u043e\u0434\u0445\u043e\u0434\u0438\u0442\u0435 \u043a \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0443 \u0442\u0438\u043f\u043e\u0432 \u0441 \u043e\u0441\u0442\u043e\u0440\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e, \u0438 \u043d\u0435 \u0431\u043e\u0439\u0442\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442. \u0413\u0438\u0431\u043a\u043e\u0441\u0442\u044c TypeScript \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u0442\u0438\u043f\u043e\u0432 \u0447\u0430\u0441\u0442\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0438 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 \u0438 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043a\u0438.<\/p>\n<p> <\/p>\n<p>\u041f\u043e\u043a\u0430-\u043f\u043e\u043a\u0430, \u0438 \u043f\u043e\u043c\u043d\u0438\u0442\u0435: <a href=\"https:\/\/lexi-lambda.github.io\/blog\/2019\/11\/05\/parse-don-t-validate\/\">\u043f\u0430\u0440\u0441\u0438\u0442\u0435, \u0430 \u043d\u0435 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u0439\u0442\u0435!<\/a><\/p>\n<p> <\/p>\n<hr\/>\n<p> <\/p>\n<blockquote><p><a href=\"https:\/\/t.me\/timewebru\"><b>\u041d\u043e\u0432\u043e\u0441\u0442\u0438, \u043e\u0431\u0437\u043e\u0440\u044b \u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432 \u0438 \u043a\u043e\u043d\u043a\u0443\u0440\u0441\u044b \u043e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b Timeweb.Cloud \u2014 \u0432 \u043d\u0430\u0448\u0435\u043c Telegram-\u043a\u0430\u043d\u0430\u043b\u0435<\/b><\/a> <b>\u21a9<\/b><\/p><\/blockquote>\n<p><a href=\"https:\/\/timeweb.cloud\/?utm_source=habr&amp;utm_medium=banner&amp;utm_campaign=promo\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/6r\/9j\/sr\/6r9jsrljpzsgcfyj1jjupubij5e.png\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/6r\/9j\/sr\/6r9jsrljpzsgcfyj1jjupubij5e.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/6r\/9j\/sr\/6r9jsrljpzsgcfyj1jjupubij5e.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/906842\/\"> https:\/\/habr.com\/ru\/articles\/906842\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-1\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg\" sizes=\"(max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/webt\/ma\/po\/lv\/mapolvqq4uunxfqoaviv3g9km9y.jpeg 781w\" loading=\"lazy\" decode=\"async\"\/> <\/p>\n<p> <\/p>\n<p> <\/p>\n<p>\u0420\u0430\u043d\u0435\u0435 \u043d\u0430 Piccalilli \u0421\u044d\u043c \u0420\u043e\u0443\u0437 <a href=\"https:\/\/piccalil.li\/blog\/real-world-uses-of-typescripts-utility-types\/\">\u043f\u043e\u0434\u0435\u043b\u0438\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 (utility types) TypeScript<\/a>. \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0438 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 TypeScript \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0438\u043f\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435, \u043d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b \u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u044b \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p> <\/p>\n<p>\u0426\u0435\u043b\u044c \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u2014 \u0434\u0430\u0442\u044c \u043e\u0431\u0449\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u043a\u0430\u043a\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0438\u043f\u043e\u0432.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-459609","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/459609","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=459609"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/459609\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=459609"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=459609"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=459609"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}