{"id":355632,"date":"2024-05-20T23:12:42","date_gmt":"2024-05-20T23:12:42","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=355632"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=355632","title":{"rendered":"<span>TypeScript \u0438 \u0432\u0441\u0435 \u0447\u0442\u043e \u0442\u0435\u0431\u0435 \u043d\u0443\u0436\u043d\u043e \u0432 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435<\/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-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1e1\/2f9\/200\/1e12f9200b6d94bddc23063ac28011f0.png\" width=\"1280\" height=\"720\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1e1\/2f9\/200\/1e12f9200b6d94bddc23063ac28011f0.png\"\/><\/figure>\n<p><em>\u0410\u0432\u0442\u043e\u0440<\/em>:\u00a0<strong>\u041c\u0430\u0441\u043b\u043e\u0432 \u0410\u043d\u0434\u0440\u0435\u0439<\/strong>, Front-end \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/p>\n<h3>\u041e \u0441\u0442\u0430\u0442\u044c\u0435<\/h3>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f TypeScript \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u0445. <\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u043a\u0430\u043a \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 TypeScript, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u044f\u0437\u044b\u043a\u0435. \u0417\u0434\u0435\u0441\u044c \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 TypeScript, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u0414\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u043e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0442\u0435\u043c\u044b TypeScript, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0439 \u0432\u0430\u0441 \u0447\u0430\u0441\u0442\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430.<\/p>\n<h3>\u041d\u0430\u0432\u0438\u0433\u0430\u0442\u043e\u0440<\/h3>\n<ul>\n<li>\n<p><a href=\"#itaut\" rel=\"noopener noreferrer nofollow\">Intersection Types \u0438 Union Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#gt\" rel=\"noopener noreferrer nofollow\">Generic Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#ut\" rel=\"noopener noreferrer nofollow\">Utility Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#ct\" rel=\"noopener noreferrer nofollow\">Conditional Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#mt\" rel=\"noopener noreferrer nofollow\">Mapped Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#tg\" rel=\"noopener noreferrer nofollow\">Type Guards<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#zac\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#mdi\" rel=\"noopener noreferrer nofollow\">\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f<\/a><\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"itaut\" id=\"itaut\"><\/a><\/p>\n<h2>Intersection Types \u0438 Union Types<\/h2>\n<h4>Intersection Types<\/h4>\n<p>\u0412 TS \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <em>\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0442\u044c<\/em> \u0442\u0438\u043f\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0438\u043f <strong>C<\/strong> \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c <em>\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/em> \u0442\u0438\u043f\u043e\u0432 <strong>\u0410 \u0438 \u0412<\/strong>. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code>type A = {   id: number   firstName: string   lastName: string  }  type B = {   id: number   height: number    weight: number }  type C = A &amp; B   \/\/\u0418\u0442\u043e\u0433 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 A \u0438 B type C = {   id: number   firstName: string   lastName: string    height: number    weight: number }<\/code><\/pre>\n<h4>Union Types<\/h4>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438 <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/em> \u0442\u0438\u043f\u043e\u0432, \u0442.\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code>type A = number  type B = string  type C = A | B  \/\/\u0418\u0442\u043e\u0433 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f A \u0438 B type C = number \u0438\u043b\u0438 string  const parseAmount = (val: C) => {   if (typeof val === 'number') {     return val    }    if (typeof val === 'string') {     return val.resplace(',', '.')   } }<\/code><\/pre>\n<p><a class=\"anchor\" name=\"gt\" id=\"gt\"><\/a><\/p>\n<h2>Generic Types<\/h2>\n<p><em>\u0414\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438<\/em> \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 TypeScript \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043d\u0430\u043c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 <em>&#171;\u043a\u043b\u043e\u043d\u043e\u0432&#187;<\/em>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0430, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<pre><code>type FetchResponse&lt;T> = {   data: T   errorMessage: string   errorCode: number }  type AuthDataRs = {   accessToken: string    refreshToken: string  }  const login = async (lg: string, ps: string): FetchResponse&lt;AuthDataRs> => {   const response = await fetch(...)    return response }  \/\/FetchResponse&lt;AuthDataRs> - \u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c  \/\/\u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FetchResponse \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e <em>\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u0442\u0438\u043f<\/em> \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430\u043c\u0438:<\/p>\n<pre><code>type FetchResponse&lt;T, P> = {   data: T   error: P }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <em>\u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/em> \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0443:<\/p>\n<pre><code>type FetchResponse&lt;T, P = string> = {   data: T   error: P }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0443 <em>\u043d\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u044f\u0432\u043d\u044b\u0439 \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/em>, \u0442\u043e \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e <em>\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0438\u043f<\/em> \u043f\u0440\u0438 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0443 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430 <em>\u0435\u0441\u0442\u044c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/em>, \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p><a class=\"anchor\" name=\"ut\" id=\"ut\"><\/a><\/p>\n<h2>Utility Types<\/h2>\n<p>\u042d\u0442\u043e \u0443\u0442\u0438\u043b\u0438\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0440\u0443\u0433\u0438\u0445. <\/p>\n<h3>Awaited<\/h3>\n<p><strong><em>Awaited&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>type A = Awaited&lt;Promise&lt;number>>; \/\/type A -> number<\/code><\/pre>\n<h3>Partial<\/h3>\n<p><strong><em>Partial&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u043a &#171;?&#187;: <\/p>\n<pre><code>type A = {   id: number    name?: string \/\/\u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435) }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Partial ? <\/p>\n<pre><code>type A = {   id: number    name: string }  type B = Partial&lt;A>  \/\/Output type B = {   id?: number \/\/\u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435)   name?: number \/\/\u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435) }<\/code><\/pre>\n<h3>Required<\/h3>\n<p><strong><em>Required&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u043a\u0430\u043a Partial. \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<pre><code>type A = {   id?: number    name?: string }  type B = Required&lt;A>  \/\/Output type B = {   id: number \/\/\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e   name: number \/\/\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e }<\/code><\/pre>\n<h3>Readonly<\/h3>\n<p><strong><em>Readonly&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0442\u0438\u043f\u0430, \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code>type A = {   id: number   name: string }  type B = Readonly&lt;A>  const firstObj: A = { id: 0, name: 'first'} const secondObj: B = { id: 1, name: 'second'}  firstObj.name = 'first_1' \/\/ it's correct secondObj.name = 'second_2' \/\/Cannot assign to 'name' because it is a read-only property.<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435 readonly \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0434 \u0438\u043c\u0435\u043d\u0435\u043c \u0441\u0432-\u0432\u0430: <\/p>\n<pre><code>type A = {   readonly id: number    name: string }<\/code><\/pre>\n<h3>Record<\/h3>\n<p><strong><em>Record&lt;T, U><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, Record&lt;Keys, Types>, \u0433\u0434\u0435 Keys &#8212; \u0438\u043c\u0435\u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0430 Types &#8212; \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0432\u043e\u0439\u0441\u0442\u0432. <\/p>\n<pre><code>enum CarNames {   AUDI = 'audi',   BMW = 'bmw' }  type CarInfo = {   color: string    price: number  }  type Cars = Record&lt;CarNames, CarInfo>  \/\/Output type Cars = {   audi: CarInfo;   bmw: CarInfo; }<\/code><\/pre>\n<h3>Pick <\/h3>\n<p><strong><em>Pick&lt;T, &#8216;key1&#8217; | &#8216;key2&#8217;><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0438\u0437 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<pre><code>type A = {   id: number    name: string  }  type B = Pick&lt;A, 'name'>  \/\/Output 1 type B = {   name: string  }  type B = Pick&lt;A, 'id' | 'name'>  \/\/Output 2 type B = {   id: number    name: string }<\/code><\/pre>\n<h3>Omit<\/h3>\n<p><strong><em>Omit&lt;T, &#8216;key1&#8217; | &#8216;key2&#8217;><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0438\u0437 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f (\u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445) \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. <\/p>\n<pre><code>type A = {   id: number    name: string  }  type B = Omit&lt;A, 'id'>  \/\/Output 1 type B = {   name: string  }  type B = Omit&lt;A, 'id' | 'name'>  \/\/Output 2 type B2 = {}<\/code><\/pre>\n<h3>Exclude<\/h3>\n<p><strong><em>Exclude&lt;T, U><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 union \u0442\u0438\u043f, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445. \u041e\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0438\u0437 T \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c U.<\/p>\n<pre><code>type A = {   id: number   name: string   length: number }  type B = {   id: number   color: string   depth: string }  type C = Exclude&lt;keyof A, keyof B>  \/\/Output  type C = \"name\" | \"length\"<\/code><\/pre>\n<h3>Extract<\/h3>\n<p><strong><em>Extract&lt;T, U><\/em><\/strong><br \/>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 union \u0442\u0438\u043f, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044f \u0438\u0437 T \u0432\u0441\u0435 \u0447\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c U. <\/p>\n<pre><code>type A = {   id: number   name: string   length: number }  type B = {   id: number   name: string   color: string   depth: string }  type C = Extract&lt;keyof A, keyof B>  \/\/Output  type C = \"id\" | \"name\"<\/code><\/pre>\n<h3>ReturnType<\/h3>\n<p><strong><em>ReturnType&lt;T><\/em><\/strong><br \/>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u0438\u043f, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0442\u0438\u043f\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 T.<\/p>\n<pre><code>type A = () => string   type B = ReturnType&lt;A>  \/\/Output type B = string<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0434\u043d\u0438 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 Utility Types,  \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u0445 \u043a \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u0433\u0434\u0435 \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 TS. <\/p>\n<p><a class=\"anchor\" name=\"ct\" id=\"ct\"><\/a><\/p>\n<h2>Conditional Types<\/h2>\n<p>\u0412 TypeScript \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430. <\/p>\n<pre><code>type ObjProps = {   id: number    name: string  }  type ExtendsObj&lt;T> = T extends ObjProps ? ObjProps : T  const obj1: ObjProps = {   id: 0,    name: 'zero' }  const obj2 = {   id: 1 }  type A = ExtendsObj&lt;typeof obj1> \/\/ type A = ObjProps type B = ExtendsObj&lt;typeof obj2> \/\/ type B = { id: number }<\/code><\/pre>\n<p><a class=\"anchor\" name=\"mt\" id=\"mt\"><\/a><\/p>\n<h2>Mapped Types<\/h2>\n<p>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0430\u043c \u0432\u0437\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0432 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<pre><code>type MapToNumber&lt;T> = {   [P in keyof T]: number }  const obj = {id: 0, depth: '1005'}  type A = MapToNumber&lt;typeof obj>  \/\/Output type A = {   id: number    depth: number  }<\/code><\/pre>\n<p><a class=\"anchor\" name=\"tg\" id=\"tg\"><\/a><\/p>\n<h2>Type Guards<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0438\u043f \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0438\u043b\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d, \u0442\u043e \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 &#171;\u0437\u0430\u0449\u0438\u0442\u0430 \u0442\u0438\u043f\u043e\u0432&#187;. <\/p>\n<h3>typeof<\/h3>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 typeof (\u0440\u0430\u043d\u0435\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439). <\/p>\n<pre><code>const fn = (val: number | string) => {   if (typeof val === 'number') {     return ...   }    throw new Error(`\u0422\u0438\u043f ${typeof val} \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d`) }<\/code><\/pre>\n<h3>in<\/h3>\n<p>\u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u0442\u0438\u043f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c in, \u044d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435.<\/p>\n<pre><code>const obj = {   id: 1,   name: 'first' }  const bool1 = 'name' in obj  \/\/true const bool2 = 'foo' in obj  \/\/false<\/code><\/pre>\n<h3>instanceof<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/p>\n<pre><code>function C() {} function D() {}  const o = new C();  o instanceof C \/\/true o instanceof D \/\/false<\/code><\/pre>\n<h3>is<\/h3>\n<p>\u042d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 TypeScript \u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 is \u0441\u0443\u0436\u0430\u0435\u0442 \u0442\u0438\u043f \u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 foo (string | number) \u0434\u043e string. \u042d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0437\u0430\u0449\u0438\u0442\u0430 \u0442\u0438\u043f\u0430. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0437\u0430\u0449\u0438\u0442\u0435  \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u0442\u0438\u043f \u0434\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u0430 if.<\/p>\n<pre><code>interface FirstName {     firstName: string }  interface FullName extends FirstName {     lastName: string }  const isFirstName = (obj: any): obj is FirstName => {     return obj &amp;&amp; typeof obj.firstName === \"string\" }  const isFullName = (obj: any): obj is FullName => {     return isFirstName(obj) &amp;&amp; typeof (obj as any).lastName === \"string\"; }  const testFn = (objInfo: FirstName | FullName | number) => {     if (isFullName(objInfo)) {         console.log('\u0422\u0438\u043f FullName')     } else if (isFirstName(objInfo)) {         console.log('\u0422\u0438\u043f FirstName')     } else {       console.log('\u0422\u0438\u043f \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 FullName \u0438\u043b\u0438 FirstName')     } }  testFn({ firstName: 'Andrey' }) \/\/\u0422\u0438\u043f FirstName testFn({ firstName: 'Andrey', lastName: 'Maslov' }) \/\/\u0422\u0438\u043f FullName testFn(1) \/\/\u0422\u0438\u043f \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 FullName \u0438\u043b\u0438 FirstName<\/code><\/pre>\n<p><a class=\"anchor\" name=\"zac\" id=\"zac\"><\/a><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, TypeScript &#8212; \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u043c \u0438 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u043c. \u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043f\u0440\u0438\u0435\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 TypeScript, \u043d\u0430\u0434 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c\u0438 \u0442\u0435\u043c\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0438 type guards.<\/p>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 TypeScript &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0438 \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u044b \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u0435\u0442\u0435\u0441\u044c, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u043c\u043e\u0449\u044c, \u043e\u0431\u0440\u0430\u0449\u0430\u0439\u0442\u0435\u0441\u044c \u043a \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 TypeScript \u0438\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u043c.<\/p>\n<p><a class=\"anchor\" name=\"mdi\" id=\"mdi\"><\/a><\/p>\n<h2>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/macloud\/articles\/559902\/\" rel=\"noopener noreferrer nofollow\">\u041e\u0441\u043d\u043e\u0432\u044b<\/a><br \/><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/utility-types.html\" rel=\"noopener noreferrer nofollow\">Utility Types<\/a><br \/><a href=\"https:\/\/www.typescriptlang.org\/cheatsheets\" rel=\"noopener noreferrer nofollow\">\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e TS \u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445<\/a><\/p>\n<\/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\/762902\/\"> https:\/\/habr.com\/ru\/articles\/762902\/<\/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-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p><em>\u0410\u0432\u0442\u043e\u0440<\/em>:\u00a0<strong>\u041c\u0430\u0441\u043b\u043e\u0432 \u0410\u043d\u0434\u0440\u0435\u0439<\/strong>, Front-end \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a.<\/p>\n<h3>\u041e \u0441\u0442\u0430\u0442\u044c\u0435<\/h3>\n<p>\u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0434\u043b\u044f \u043e\u0431\u043b\u0435\u0433\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f TypeScript \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432. \u0411\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u043b\u0438 \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u0445. <\/p>\n<p>\u0421\u0442\u0430\u0442\u044c\u044f \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u043a\u0430\u043a \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 TypeScript, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043e\u043f\u044b\u0442\u043d\u044b\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u0443\u0433\u043b\u0443\u0431\u0438\u0442\u044c \u0441\u0432\u043e\u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u0432 \u044d\u0442\u043e\u043c \u044f\u0437\u044b\u043a\u0435. \u0417\u0434\u0435\u0441\u044c \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0432\u043d\u043e\u0435 \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 TypeScript, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u0439 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u0414\u043b\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430, \u043e\u0433\u043b\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u0442\u0435\u043c\u044b TypeScript, \u0442\u0430\u043a \u0447\u0442\u043e \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0439 \u0432\u0430\u0441 \u0447\u0430\u0441\u0442\u0438 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430.<\/p>\n<h3>\u041d\u0430\u0432\u0438\u0433\u0430\u0442\u043e\u0440<\/h3>\n<ul>\n<li>\n<p><a href=\"#itaut\" rel=\"noopener noreferrer nofollow\">Intersection Types \u0438 Union Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#gt\" rel=\"noopener noreferrer nofollow\">Generic Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#ut\" rel=\"noopener noreferrer nofollow\">Utility Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#ct\" rel=\"noopener noreferrer nofollow\">Conditional Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#mt\" rel=\"noopener noreferrer nofollow\">Mapped Types<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#tg\" rel=\"noopener noreferrer nofollow\">Type Guards<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#zac\" rel=\"noopener noreferrer nofollow\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"#mdi\" rel=\"noopener noreferrer nofollow\">\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f<\/a><\/p>\n<\/li>\n<\/ul>\n<p><a class=\"anchor\" name=\"itaut\" id=\"itaut\"><\/a><\/p>\n<h2>Intersection Types \u0438 Union Types<\/h2>\n<h4>Intersection Types<\/h4>\n<p>\u0412 TS \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <em>\u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u0442\u044c<\/em> \u0442\u0438\u043f\u044b. \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0442\u0438\u043f <strong>C<\/strong> \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c <em>\u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f<\/em> \u0442\u0438\u043f\u043e\u0432 <strong>\u0410 \u0438 \u0412<\/strong>. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code>type A = {   id: number   firstName: string   lastName: string  }  type B = {   id: number   height: number    weight: number }  type C = A &amp; B   \/\/\u0418\u0442\u043e\u0433 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 A \u0438 B type C = {   id: number   firstName: string   lastName: string    height: number    weight: number }<\/code><\/pre>\n<h4>Union Types<\/h4>\n<p>\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u044e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0438 <em>\u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435<\/em> \u0442\u0438\u043f\u043e\u0432, \u0442.\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u043e\u0432 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435:<\/p>\n<pre><code>type A = number  type B = string  type C = A | B  \/\/\u0418\u0442\u043e\u0433 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f A \u0438 B type C = number \u0438\u043b\u0438 string  const parseAmount = (val: C) => {   if (typeof val === 'number') {     return val    }    if (typeof val === 'string') {     return val.resplace(',', '.')   } }<\/code><\/pre>\n<p><a class=\"anchor\" name=\"gt\" id=\"gt\"><\/a><\/p>\n<h2>Generic Types<\/h2>\n<p><em>\u0414\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438<\/em> \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 TypeScript \u0432 \u043f\u043e\u0432\u0441\u0435\u0434\u043d\u0435\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044f \u043d\u0430\u043c \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b, \u0438\u0437\u0431\u0435\u0433\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0430 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 <em>&#171;\u043a\u043b\u043e\u043d\u043e\u0432&#187;<\/em>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0438\u043f\u0430, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432.<\/p>\n<pre><code>type FetchResponse&lt;T> = {   data: T   errorMessage: string   errorCode: number }  type AuthDataRs = {   accessToken: string    refreshToken: string  }  const login = async (lg: string, ps: string): FetchResponse&lt;AuthDataRs> => {   const response = await fetch(...)    return response }  \/\/FetchResponse&lt;AuthDataRs> - \u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0432\u0430\u043c  \/\/\u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c FetchResponse \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432.<\/code><\/pre>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043c\u043e\u0436\u043d\u043e <em>\u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0442\u044c \u0441\u0432\u043e\u0439 \u0442\u0438\u043f<\/em> \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430\u043c\u0438:<\/p>\n<pre><code>type FetchResponse&lt;T, P> = {   data: T   error: P }<\/code><\/pre>\n<p>\u0422\u0430\u043a \u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 <em>\u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0442\u044c \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/em> \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0443:<\/p>\n<pre><code>type FetchResponse&lt;T, P = string> = {   data: T   error: P }<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0443 <em>\u043d\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u044f\u0432\u043d\u044b\u0439 \u0442\u0438\u043f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e<\/em>, \u0442\u043e \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e <em>\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0438\u043f<\/em> \u043f\u0440\u0438 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u0443 \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430 <em>\u0435\u0441\u0442\u044c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/em>, \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0442\u0438\u043f\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0432\u043e\u0432\u0441\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f.<\/p>\n<p><a class=\"anchor\" name=\"ut\" id=\"ut\"><\/a><\/p>\n<h2>Utility Types<\/h2>\n<p>\u042d\u0442\u043e \u0443\u0442\u0438\u043b\u0438\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u0440\u0443\u0433\u0438\u0445. <\/p>\n<h3>Awaited<\/h3>\n<p><strong><em>Awaited&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code>type A = Awaited&lt;Promise&lt;number>>; \/\/type A -> number<\/code><\/pre>\n<h3>Partial<\/h3>\n<p><strong><em>Partial&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0433\u0434\u0435 \u043a\u0430\u0436\u0434\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0441\u0442\u0430\u043d\u0435\u0442 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c. \u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u043a &#171;?&#187;: <\/p>\n<pre><code>type A = {   id: number    name?: string \/\/\u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435) }<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 Partial ? <\/p>\n<pre><code>type A = {   id: number    name: string }  type B = Partial&lt;A>  \/\/Output type B = {   id?: number \/\/\u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435)   name?: number \/\/\u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e (\u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435) }<\/code><\/pre>\n<h3>Required<\/h3>\n<p><strong><em>Required&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442 \u043a\u0430\u043a Partial. \u0421\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<pre><code>type A = {   id?: number    name?: string }  type B = Required&lt;A>  \/\/Output type B = {   id: number \/\/\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e   name: number \/\/\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e }<\/code><\/pre>\n<h3>Readonly<\/h3>\n<p><strong><em>Readonly&lt;T><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0442\u0438\u043f\u0430, \u0434\u0435\u043b\u0430\u0435\u0442 \u0438\u0445 \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u043e\u0432\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<pre><code>type A = {   id: number   name: string }  type B = Readonly&lt;A>  const firstObj: A = { id: 0, name: 'first'} const secondObj: B = { id: 1, name: 'second'}  firstObj.name = 'first_1' \/\/ it's correct secondObj.name = 'second_2' \/\/Cannot assign to 'name' because it is a read-only property.<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0435 readonly \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u043f\u0435\u0440\u0435\u0434 \u0438\u043c\u0435\u043d\u0435\u043c \u0441\u0432-\u0432\u0430: <\/p>\n<pre><code>type A = {   readonly id: number    name: string }<\/code><\/pre>\n<h3>Record<\/h3>\n<p><strong><em>Record&lt;T, U><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, Record&lt;Keys, Types>, \u0433\u0434\u0435 Keys &#8212; \u0438\u043c\u0435\u043d\u0430 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0430 Types &#8212; \u0442\u0438\u043f\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0441\u0432\u043e\u0439\u0441\u0442\u0432. <\/p>\n<pre><code>enum CarNames {   AUDI = 'audi',   BMW = 'bmw' }  type CarInfo = {   color: string    price: number  }  type Cars = Record&lt;CarNames, CarInfo>  \/\/Output type Cars = {   audi: CarInfo;   bmw: CarInfo; }<\/code><\/pre>\n<h3>Pick <\/h3>\n<p><strong><em>Pick&lt;T, &#8216;key1&#8217; | &#8216;key2&#8217;><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u0438\u0437 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430.<\/p>\n<pre><code>type A = {   id: number    name: string  }  type B = Pick&lt;A, 'name'>  \/\/Output 1 type B = {   name: string  }  type B = Pick&lt;A, 'id' | 'name'>  \/\/Output 2 type B = {   id: number    name: string }<\/code><\/pre>\n<h3>Omit<\/h3>\n<p><strong><em>Omit&lt;T, &#8216;key1&#8217; | &#8216;key2&#8217;><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0438\u0437 \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0445\u0441\u044f (\u043d\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u044b\u0445) \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430. <\/p>\n<pre><code>type A = {   id: number    name: string  }  type B = Omit&lt;A, 'id'>  \/\/Output 1 type B = {   name: string  }  type B = Omit&lt;A, 'id' | 'name'>  \/\/Output 2 type B2 = {}<\/code><\/pre>\n<h3>Exclude<\/h3>\n<p><strong><em>Exclude&lt;T, U><\/em><\/strong><br \/>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 union \u0442\u0438\u043f, \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u0434\u0432\u0443\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u0430\u0445. \u041e\u043d \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0438\u0437 T \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c U.<\/p>\n<pre><code>type A = {   id: number   name: string   length: number }  type B = {   id: number   color: string   depth: string }  type C = Exclude&lt;keyof A, keyof B>  \/\/Output  type C = \"name\" | \"length\"<\/code><\/pre>\n<h3>Extract<\/h3>\n<p><strong><em>Extract&lt;T, U><\/em><\/strong><br \/>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 union \u0442\u0438\u043f, \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044f \u0438\u0437 T \u0432\u0441\u0435 \u0447\u043b\u0435\u043d\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c U. <\/p>\n<pre><code>type A = {   id: number   name: string   length: number }  type B = {   id: number   name: string   color: string   depth: string }  type C = Extract&lt;keyof A, keyof B>  \/\/Output  type C = \"id\" | \"name\"<\/code><\/pre>\n<h3>ReturnType<\/h3>\n<p><strong><em>ReturnType&lt;T><\/em><\/strong><br \/>\u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u0442\u0438\u043f, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0442\u0438\u043f\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 T.<\/p>\n<pre><code>type A = () => string   type B = ReturnType&lt;A>  \/\/Output type B = string<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043e\u0434\u043d\u0438 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 Utility Types,  \u0432 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u0445 \u043a \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u0433\u0434\u0435 \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 TS. <\/p>\n<p><a class=\"anchor\" name=\"ct\" id=\"ct\"><\/a><\/p>\n<h2>Conditional Types<\/h2>\n<p>\u0412 TypeScript \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0430. <\/p>\n<pre><code>type ObjProps = {   id: number    name: string  }  type ExtendsObj&lt;T> = T extends ObjProps ? ObjProps : T  const obj1: ObjProps = {   id: 0,    name: 'zero' }  const obj2 = {   id: 1 }  type A = ExtendsObj&lt;typeof obj1> \/\/ type A = ObjProps type B = ExtendsObj&lt;typeof obj2> \/\/ type B = { id: number }<\/code><\/pre>\n<p><a class=\"anchor\" name=\"mt\" id=\"mt\"><\/a><\/p>\n<h2>Mapped Types<\/h2>\n<p>\u0421\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0432\u0430\u043c \u0432\u0437\u044f\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0438 \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u043e\u0435 \u0438\u0437 \u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0432 \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f.<\/p>\n<pre><code>type MapToNumber&lt;T> = {   [P in keyof T]: number }  const obj = {id: 0, depth: '1005'}  type A = MapToNumber&lt;typeof obj>  \/\/Output type A = {   id: number    depth: number  }<\/code><\/pre>\n<p><a class=\"anchor\" name=\"tg\" id=\"tg\"><\/a><\/p>\n<h2>Type Guards<\/h2>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0438\u043f \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d \u0438\u043b\u0438 \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u0435\u043d, \u0442\u043e \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 &#171;\u0437\u0430\u0449\u0438\u0442\u0430 \u0442\u0438\u043f\u043e\u0432&#187;. <\/p>\n<h3>typeof<\/h3>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u0438\u0442\u044c \u0441\u0435\u0431\u044f \u043e\u0442 \u043e\u0448\u0438\u0431\u043a\u0438, \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 typeof (\u0440\u0430\u043d\u0435\u0435 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445 \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u0438\u0434\u0435\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u0438\u043f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439). <\/p>\n<pre><code>const fn = (val: number | string) => {   if (typeof val === 'number') {     return ...   }    throw new Error(`\u0422\u0438\u043f ${typeof val} \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d`) }<\/code><\/pre>\n<h3>in<\/h3>\n<p>\u0415\u0449\u0435 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0437\u0430\u0449\u0438\u0442\u0438\u0442\u044c \u0442\u0438\u043f, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c in, \u044d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435.<\/p>\n<pre><code>const obj = {   id: 1,   name: 'first' }  const bool1 = 'name' in obj  \/\/true const bool2 = 'foo' in obj  \/\/false<\/code><\/pre>\n<h3>instanceof<\/h3>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0430 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0433\u0434\u0435-\u043d\u0438\u0431\u0443\u0434\u044c \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/p>\n<pre><code>function C() {} function D() {}  const o = new C();  o instanceof C \/\/true o instanceof D \/\/false<\/code><\/pre>\n<h3>is<\/h3>\n<p>\u042d\u0442\u043e\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 TypeScript \u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0435\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 true. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0438\u0436\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 is \u0441\u0443\u0436\u0430\u0435\u0442 \u0442\u0438\u043f \u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 foo (string | number) \u0434\u043e string. \u042d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0437\u0430\u0449\u0438\u0442\u0430 \u0442\u0438\u043f\u0430. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0437\u0430\u0449\u0438\u0442\u0435  \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u0442\u0438\u043f \u0434\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0431\u043b\u043e\u043a\u0430 if.<\/p>\n<pre><code>interface FirstName {     firstName: string }  interface FullName extends FirstName {     lastName: string }  const isFirstName = (obj: any): obj is FirstName => {     return obj &amp;&amp; typeof obj.firstName === \"string\" }  const isFullName = (obj: any): obj is FullName => {     return isFirstName(obj) &amp;&amp; typeof (obj as any).lastName === \"string\"; }  const testFn = (objInfo: FirstName | FullName | number) => {     if (isFullName(objInfo)) {         console.log('\u0422\u0438\u043f FullName')     } else if (isFirstName(objInfo)) {         console.log('\u0422\u0438\u043f FirstName')     } else {       console.log('\u0422\u0438\u043f \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 FullName \u0438\u043b\u0438 FirstName')     } }  testFn({ firstName: 'Andrey' }) \/\/\u0422\u0438\u043f FirstName testFn({ firstName: 'Andrey', lastName: 'Maslov' }) \/\/\u0422\u0438\u043f FullName testFn(1) \/\/\u0422\u0438\u043f \u043d\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 FullName \u0438\u043b\u0438 FirstName<\/code><\/pre>\n<p><a class=\"anchor\" name=\"zac\" id=\"zac\"><\/a><\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u0442\u0435, TypeScript &#8212; \u044d\u0442\u043e \u043c\u043e\u0449\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u043c \u0438 \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u043c. \u0412 \u044d\u0442\u043e\u043c \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043f\u0440\u0438\u0435\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0441 TypeScript, \u043d\u0430\u0434 \u0442\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c\u0438 \u0442\u0435\u043c\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u0430\u043a \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0438 type guards.<\/p>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435, \u0447\u0442\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0435 TypeScript &#8212; \u044d\u0442\u043e \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0438 \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u044b \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u0435\u0442\u0435\u0441\u044c, \u0442\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445. <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442 \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u043f\u043e\u043c\u043e\u0449\u044c, \u043e\u0431\u0440\u0430\u0449\u0430\u0439\u0442\u0435\u0441\u044c \u043a \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 TypeScript \u0438\u043b\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430\u043c.<\/p>\n<p><a class=\"anchor\" name=\"mdi\" id=\"mdi\"><\/a><\/p>\n<h2>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b \u0434\u043b\u044f \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f<\/h2>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/macloud\/articles\/559902\/\" rel=\"noopener noreferrer nofollow\">\u041e\u0441\u043d\u043e\u0432\u044b<\/a><br \/><a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/utility-types.html\" rel=\"noopener noreferrer nofollow\">Utility Types<\/a><br \/><a href=\"https:\/\/www.typescriptlang.org\/cheatsheets\" rel=\"noopener noreferrer nofollow\">\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e TS \u0432 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u0445<\/a><\/p>\n<\/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\/762902\/\"> https:\/\/habr.com\/ru\/articles\/762902\/<\/a><br \/><\/br><\/br><\/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-355632","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355632","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=355632"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/355632\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=355632"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=355632"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=355632"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}