{"id":324217,"date":"2021-06-02T15:01:09","date_gmt":"2021-06-02T15:01:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324217"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324217","title":{"rendered":"\u041a\u0430\u0440\u043c\u0430\u043d\u043d\u0430\u044f \u043a\u043d\u0438\u0433\u0430 \u043f\u043e TypeScript. \u0427\u0430\u0441\u0442\u044c 3. \u0421\u0443\u0436\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ad\/rw\/w4\/adrww41gv8k_vuxeswr0-xkl57y.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0435\u0440\u0438\u044e \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/intro.html\"><code> &quot;\u041a\u0430\u0440\u043c\u0430\u043d\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438 \u043f\u043e TypeScript<\/code>&quot;.<\/a>  <\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/559902\/\">\u0427\u0430\u0441\u0442\u044c 1. \u041e\u0441\u043d\u043e\u0432\u044b<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/559976\/\">\u0427\u0430\u0441\u0442\u044c 2. \u0422\u0438\u043f\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>padLeft<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function padLeft(padding: number | string, input: string): string {  throw new Error('\u0415\u0449\u0435 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e!') }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 <code>padding<\/code> \u2014 \u044d\u0442\u043e <code>number<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043f\u0435\u0440\u0435\u0434 <code>input<\/code>. \u0415\u0441\u043b\u0438 <code>padding<\/code> \u2014 \u044d\u0442\u043e <code>string<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>padding<\/code> \u043f\u0435\u0440\u0435\u0434 <code>input<\/code>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0433\u0434\u0430 <code>padLeft<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <code>number<\/code> \u0434\u043b\u044f <code>padding<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function padLeft(padding: number | string, input: string): string {  return new Array(padding + 1).join(' ') + input  \/\/ Operator '+' cannot be applied to types 'string | number' and 'number'. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 '+' \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d \u043a \u0442\u0438\u043f\u0430\u043c 'string | number' }<\/code><\/pre>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443. <code>TS<\/code> \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0430\u0435\u0442 \u043d\u0430\u0441 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <code>number<\/code> \u043a <code>number | string<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443, \u0438 \u043e\u043d \u043f\u0440\u0430\u0432. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0442\u0438\u043f <code>padding<\/code> \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u043a\u0438\u0445-\u043b\u0438\u0431\u043e \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441 \u043d\u0438\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function padLeft(padding: number | string, input: string): string {  if (typeof padding === 'number') {    return new Array(padding + 1).join(' ') + input  }  return padding + input }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>typeof padding === 'number'<\/code> \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u0449\u0438\u0442\u043d\u0438\u043a\u043e\u043c \u0438\u043b\u0438 \u043f\u0440\u0435\u0434\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u0435\u043c \u0442\u0438\u043f\u0430 (type guard). \u0410 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043a \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u0449\u0438\u0442\u043d\u0438\u043a\u043e\u0432 \u0442\u0438\u043f\u0430 \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0439 \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u0435\u043c \u0442\u0438\u043f\u0430 (narrowing).<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function padLeft(padding: number | string, input: string) {  if (typeof padding === &quot;number&quot;) {    return new Array(padding + 1).join(&quot; &quot;) + input;                    \/\/ (parameter) padding: number  }  return padding + input;        \/\/ (parameter) padding: string }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439.<\/p>\n<p>  <\/p>\n<h2 id=\"zaschitnik-tipa-typeof\">\u0417\u0430\u0449\u0438\u0442\u043d\u0438\u043a \u0442\u0438\u043f\u0430 <code>typeof<\/code><\/h2>\n<p>  <\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>typeof<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0438\u0437 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0440\u043e\u043a:<\/p>\n<p>  <\/p>\n<ul>\n<li>&quot;string&quot;<\/li>\n<li>&quot;number&quot;<\/li>\n<li>&quot;bigint&quot;<\/li>\n<li>&quot;boolean&quot;<\/li>\n<li>&quot;symbol&quot;<\/li>\n<li>&quot;undefined&quot;<\/li>\n<li>&quot;object&quot;<\/li>\n<li>&quot;function&quot;<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function printAll(strs: string | string[] | null) {  if (typeof strs === &quot;object&quot;) {    for (const s of strs) {      \/\/ Object is possibly 'null'. \u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f 'null'      console.log(s);    }  } else if (typeof strs === &quot;string&quot;) {    console.log(strs);  } else {    \/\/ ...  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>printAll<\/code> \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>strs<\/code> \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c (\u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c). \u041d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>typeof null<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>object<\/code> (\u043f\u043e \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c), \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443.<\/p>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u0441\u0443\u0436\u0435\u043d\u0438\u0435 \u043a <code>string[] | null<\/code> \u0432\u043c\u0435\u0441\u0442\u043e \u0436\u0435\u043b\u0430\u0435\u043c\u043e\u0433\u043e <code>string[]<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"proverka-na-istinnost-truthiness-narrowing\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u044c (truthiness narrowing)<\/h2>\n<p>  <\/p>\n<p>\u0412 <code>JS<\/code> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445, \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u0445 <code>&amp;&amp;<\/code>, <code>||<\/code>, <code>if<\/code>, \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043a \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>!<\/code> \u0438 \u0442.\u0434. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>if<\/code> \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u0442\u0438\u043f <code>boolean<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getUsersOnlineMessage(numUsersOnline: number) {  if (numUsersOnline) {    return `\u0412 \u0441\u0435\u0442\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f ${numUsersOnline} \u0447\u0435\u043b\u043e\u0432\u0435\u043a!`;  }  return &quot;\u0417\u0434\u0435\u0441\u044c \u043d\u0438\u043a\u043e\u0433\u043e \u043d\u0435\u0442 :(&quot;; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 <code>JS<\/code> \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0442\u0438\u043f\u0430 <code>if<\/code> \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u0431\u0438\u0440\u0430\u044e\u0442 \u0432\u0435\u0442\u043a\u0443 (\u0441 \u043a\u043e\u0434\u043e\u043c \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f) \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 (<code>true<\/code> \u0438\u043b\u0438 <code>false<\/code>). \u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f<\/p>\n<p>  <\/p>\n<ul>\n<li>0<\/li>\n<li>NaN<\/li>\n<li>&quot;&quot; (\u043f\u0443\u0441\u0442\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430)<\/li>\n<li>0n (bigint-\u0432\u0435\u0440\u0441\u0438\u044f \u043d\u0443\u043b\u044f)<\/li>\n<li>null<\/li>\n<li>undefined<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043b\u043e\u0436\u043d\u044b\u043c\u0438, \u0442.\u0435. \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 <code>false<\/code>, \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c\u0438, \u0442.\u0435. \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442\u0441\u044f \u0432 <code>true<\/code>. \u042f\u0432\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>Boolean<\/code> \u0438\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0432\u043e\u0439\u043d\u043e\u0433\u043e \u043e\u0442\u0440\u0438\u0446\u0430\u043d\u0438\u044f (<code>!!<\/code>):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/\/ \u043e\u0431\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 `true` Boolean('hello') !!'world'<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0442\u0435\u0445\u043d\u0438\u043a\u0430 \u0448\u0438\u0440\u043e\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <code>null<\/code> \u0438 <code>undefined<\/code>. \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u043c \u0435\u0435 \u043a \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>printAll<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function printAll(strs: string | string[] | null) {  if (strs &amp;&amp; typeof strs === &quot;object&quot;) {    for (const s of strs) {      console.log(s);    }  } else if (typeof strs === &quot;string&quot;) {    console.log(strs);  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e <code>strs<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0441\u0442\u0438\u043d\u043d\u044b\u043c. \u042d\u0442\u043e \u0437\u0430\u0449\u0438\u0449\u0430\u0435\u0442 \u043d\u0430\u0441 \u043e\u0442 \u0442\u0430\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a \u043a\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">TypeError: null is not iterable \u041e\u0448\u0438\u0431\u043a\u0430 \u0442\u0438\u043f\u0430: null \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0442\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u043e\u0439 (\u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0435\u043c\u043e\u0439) \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>, \u0447\u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043e\u0432 \u043d\u0430 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0440\u0443\u0433\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>printAll<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function printAll(strs: string | string[] | null) {  \/\/ !!!  \/\/  \u041d\u0415 \u041d\u0410\u0414\u041e \u0422\u0410\u041a \u0414\u0415\u041b\u0410\u0422\u042c  \/\/ !!!  if (strs) {    if (typeof strs === &quot;object&quot;) {      for (const s of strs) {        console.log(s);      }    } else if (typeof strs === &quot;string&quot;) {      console.log(strs);    }  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043e\u0431\u0435\u0440\u043d\u0443\u043b\u0438 \u0442\u0435\u043b\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u0438\u0441\u0442\u0438\u043d\u043d\u043e\u0441\u0442\u044c, \u043d\u043e \u0443 \u0442\u0430\u043a\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u043a: \u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 &quot;\u041d\u0415&quot;:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function multiplyAll(  values: number[] | undefined,  factor: number ): number[] | undefined {  if (!values) {    return values  } else {    return values.map((x) =&gt; x * factor)  } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"proverka-na-ravenstvo-equality-narrowing\">\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e (equality narrowing)<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 <code>switch<\/code> \u0438\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 <code>===<\/code>, <code>!==<\/code>, <code>==<\/code>, <code>!=<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function example(x: string | number, y: string | boolean) {  if (x === y) {    \/\/ \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434    x.toUpperCase()    \/\/ (method) String.toUpperCase(): string    y.toLowerCase()    \/\/ (method) String.toLowerCase(): string  } else {    console.log(x)            \/\/ (parameter) x: string | number    console.log(y)            \/\/ (parameter) y: string | boolean  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <code>x<\/code> \u0438 <code>y<\/code>, <code>TS<\/code> \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0438\u0445 \u0442\u0438\u043f\u044b \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0440\u0430\u0432\u043d\u044b. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>string<\/code> \u2014 \u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043e\u0431\u0449\u0438\u0439 \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u043b\u0430\u0434\u0430\u044e\u0442 \u0438 <code>x<\/code>, \u0438 <code>y<\/code>, <code>TS<\/code> \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e <code>x<\/code> \u0438 <code>y<\/code> \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c <code>string<\/code> \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0442\u043a\u0435.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u043d\u0430\u0448\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>printAll<\/code> \u0431\u044b\u043b\u0430 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430\u043c, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043c\u044b \u043d\u0435\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0438 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0443\u0441\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u0435\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function printAll(strs: string | string[] | null) {  if (strs !== null) {    if (typeof strs === &quot;object&quot;) {      for (const s of strs) {                    \/\/ (parameter) strs: string[]        console.log(s);      }    } else if (typeof strs === &quot;string&quot;) {      console.log(strs);                \/\/ (parameter) strs: string    }  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 (<code>==<\/code> \u0438 <code>!=<\/code>) \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u0436\u0435 \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e, \u0447\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u0441\u0442\u0440\u043e\u0433\u043e\u0433\u043e \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u0430 (<code>===<\/code> \u0438 <code>!==<\/code>). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>== null<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 <code>null<\/code>, \u043d\u043e \u0438 \u0441 <code>undefined<\/code>. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>== undefined<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043d\u0430 \u0440\u0430\u0432\u0435\u043d\u0441\u0442\u0432\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 <code>undefined<\/code>, \u043d\u043e \u0438 \u0441 <code>null<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">interface Container {  value: number | null | undefined; }  function multiplyValue(container: Container, factor: number) {  \/\/ \u0423\u0434\u0430\u043b\u044f\u0435\u043c 'null' \u0438 'undefined' \u0438\u0437 \u0442\u0438\u043f\u0430  if (container.value != null) {    console.log(container.value);                \/\/ (property) Container.value: number     \/\/ \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0443\u043c\u043d\u043e\u0436\u0430\u0442\u044c 'container.value'    container.value *= factor;  } }<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"suzhenie-tipov-s-pomoschyu-operatora-in\">\u0421\u0443\u0436\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>in<\/code><\/h3>\n<p>  <\/p>\n<p>\u0412 <code>JS<\/code> \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u2014 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>in<\/code>. <code>TS<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u0434\u043b\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0435\u0442\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0438 <code>'value' in x<\/code>, \u0433\u0434\u0435 &#8216;value&#8217; \u2014 \u0441\u0442\u0440\u043e\u043a\u0430, \u0430 <code>x<\/code> \u2014 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435, \u0438\u0441\u0442\u0438\u043d\u043d\u0430\u044f \u0432\u0435\u0442\u043a\u0430 \u0441\u0443\u0436\u0430\u0435\u0442 \u0442\u0438\u043f\u044b <code>x<\/code> \u043a \u0442\u0438\u043f\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>value<\/code>, \u0430 \u043b\u043e\u0436\u043d\u0430\u044f \u0432\u0435\u0442\u043a\u0430 \u0441\u0443\u0436\u0430\u0435\u0442 \u0442\u0438\u043f\u044b \u043a \u0442\u0438\u043f\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u044e\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">type Fish = { swim: () =&gt; void }; type Bird = { fly: () =&gt; void };  function move(animal: Fish | Bird) {  if (&quot;swim&quot; in animal) {    return animal.swim();  }   return animal.fly(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u0432 \u043e\u0431\u043e\u0438\u0445 \u0432\u0435\u0442\u043a\u0430\u0445 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u043e\u0439, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0436\u0435\u0442 \u0438 \u043f\u043b\u0430\u0432\u0430\u0442\u044c (swim), \u0438 \u043b\u0435\u0442\u0430\u0442\u044c (fly) (\u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043d\u0430\u0440\u044f\u0436\u0435\u043d\u0438\u044f):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">type Fish = { swim: () =&gt; void }; type Bird = { fly: () =&gt; void }; type Human = {  swim?: () =&gt; void, fly?: () =&gt; void };  function move(animal: Fish | Bird | Human) {  if (&quot;swim&quot; in animal) {    animal    \/\/ (parameter) animal: Fish | Human  } else {    animal    \/\/ (parameter) animal: Bird | Human  } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"suzhenie-tipov-s-pomoschyu-operatora-instanceof\">\u0421\u0443\u0436\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 <code>instanceof<\/code><\/h2>\n<p>  <\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 <code>instanceof<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043e\u0434\u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c &quot;\u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c&quot; \u0434\u0440\u0443\u0433\u043e\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>x instanceof Foo<\/code> \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043b\u0438 <code>Foo.prototype<\/code> \u0432 \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432 <code>x<\/code>. \u0414\u0430\u043d\u043d\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c, \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 <code>new<\/code>. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function logValue(x: Date | string) {  if (x instanceof Date) {    console.log(x.toUTCString());              \/\/ (parameter) x: Date  } else {    console.log(x.toUpperCase());              \/\/ (parameter) x: string  } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"prisvoeniya-assignments\">\u041f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f (assignments)<\/h2>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u043d\u0435\u0435, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, <code>TS<\/code> &quot;\u0441\u043c\u043e\u0442\u0440\u0438\u0442&quot; \u043d\u0430 \u043f\u0440\u0430\u0432\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0442\u0438\u043f \u0434\u043b\u044f \u043b\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">let x = Math.random() &lt; 0.5 ? 10 : &quot;hello world!&quot;;  \/\/ let x: string | number  x = 1;  console.log(x);          \/\/ let x: number  x = &quot;goodbye!&quot;;  console.log(x);          \/\/ let x: string<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u043c\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0438\u043f\u043e\u043c, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0434\u043b\u044f <code>x<\/code>, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>string | number<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043f\u0440\u0438\u0441\u0432\u043e\u0438\u0442\u044c <code>x<\/code> \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043e\u0448\u0438\u0431\u043a\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">x = true; \/\/ Type 'boolean' is not assignable to type 'string | number'.  console.log(x);          \/\/ let x: string | number<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"analiz-potoka-upravleniya\">\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>\u0410\u043d\u0430\u043b\u0438\u0437 \u043f\u043e\u0442\u043e\u043a\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f (control flow analysis) \u2014 \u044d\u0442\u043e \u0430\u043d\u0430\u043b\u0438\u0437, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u0439 <code>TS<\/code> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0434\u043e\u0441\u0442\u0438\u0436\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 (reachability) \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0438\u043c \u0434\u043b\u044f \u0441\u0443\u0436\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u043e\u0432 \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0437\u0430\u0449\u0438\u0442\u043d\u0438\u043a\u043e\u0432 \u0442\u0438\u043f\u0430 \u0438 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u0439. \u041f\u0440\u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u043f\u043e\u0442\u043e\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c\u0441\u044f \u0438 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u0430\u0445 \u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function example() {  let x: string | number | boolean;   x = Math.random() &lt; 0.5;   console.log(x);            \/\/ let x: boolean   if (Math.random() &lt; 0.5) {    x = &quot;hello&quot;;    console.log(x);              \/\/ let x: string  } else {    x = 100;    console.log(x);              \/\/ let x: number  }   return x;      \/\/ let x: string | number }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"ispolzovanie-predikatov-tipa-type-predicates\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 (type predicates)<\/h2>\n<p>  <\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u044f\u043c\u043e\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0442\u0438\u043f\u044b. \u0414\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0437\u0430\u0449\u0438\u0442\u043d\u0438\u043a\u0430 \u0442\u0438\u043f\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <a href=\"https:\/\/habr.com\/ru\/post\/310172\/#:~:text=%D0%9F%D1%80%D0%B5%D0%B4%D0%B8%D0%BA%D0%B0%D1%82%20%E2%80%94%20%D1%8D%D1%82%D0%BE%20%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D1%8F%2C%20%D0%BA%D0%BE%D1%82%D0%BE%D1%80%D0%B0%D1%8F%20%D0%B2%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%89%D0%B0%D0%B5%D1%82,(callback)%20%D0%B4%D0%BB%D1%8F%20%D1%84%D0%B8%D0%BB%D1%8C%D1%82%D1%80%D0%B0%20%D0%BC%D0%B0%D1%81%D1%81%D0%B8%D0%B2%D0%B0.\">\u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442<\/a> \u0442\u0438\u043f\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function isFish(pet: Fish | Bird): pet is Fish {  return (pet as Fish).swim !== undefined }<\/code><\/pre>\n<p>  <\/p>\n<p><code>pet is Fish<\/code> \u2014 \u044d\u0442\u043e \u043d\u0430\u0448 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442. \u041f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0438\u043c\u0435\u0435\u0442 \u0444\u043e\u0440\u043c\u0443 <code>parameterName is Type<\/code>, \u0433\u0434\u0435 <code>parameterName<\/code> \u2014 \u044d\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0438\u0437 <a href=\"https:\/\/ru.wikipedia.org\/wiki\/API#%D0%A1%D0%B8%D0%B3%D0%BD%D0%B0%D1%82%D1%83%D1%80%D0%B0_%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D0%B8\">\u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b<\/a> \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 <code>isFish<\/code> \u0441 \u043b\u044e\u0431\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, <code>TS<\/code> &quot;\u0441\u0443\u0437\u0438\u0442&quot; \u044d\u0442\u0443 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u0434\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430, \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c \u0441 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">const pet = getSmallPet()  if (isFish(pet)) {  pet.swim() } else {  pet.fly() }<\/code><\/pre>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435<\/em>: <code>TS<\/code> \u0437\u043d\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e, \u0447\u0442\u043e <code>pet<\/code> \u2014 \u044d\u0442\u043e <code>Fish<\/code> \u0432 \u0432\u0435\u0442\u043a\u0435 <code>if<\/code>, \u043d\u043e \u0442\u0430\u043a\u0436\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432 \u0432\u0435\u0442\u043a\u0435 <code>else<\/code> <code>pet<\/code> \u2014 \u044d\u0442\u043e <code>Bird<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u0449\u0438\u0442\u043d\u0438\u043a\u0430 <code>isFish<\/code> \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>Fish | Bird<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>Fish<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">const zoo: (Fish | Bird)[] = [getSmallPet(), getSmallPet(), getSmallPet()] const underWater1: Fish[] = zoo.filter(isFish) \/\/ \u0438\u043b\u0438 const underWater2: Fish[] = zoo.filter(isFish) as Fish[]  \/\/ \u0412 \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u0430 const underWater3: Fish[] = zoo.filter((pet): pet is Fish =&gt; {  if (pet.name === 'sharkey') return false  return isFish(pet) })<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"isklyuchayuschie-obedineniya-discriminated-unions\">\u0418\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f (discriminated unions)<\/h2>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0437\u0430\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0438\u0433\u0443\u0440\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043a\u0440\u0443\u0433\u0438 \u0438 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b. \u041a\u0440\u0443\u0433\u0438 &quot;\u0441\u043b\u0435\u0434\u044f\u0442&quot; \u0437\u0430 \u0440\u0430\u0434\u0438\u0443\u0441\u043e\u043c, \u0430 \u043a\u0432\u0430\u0434\u0440\u0430\u0442\u044b \u2014 \u0437\u0430 \u0434\u043b\u0438\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b. \u0414\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0441 \u043a\u0430\u043a\u043e\u0439 \u0444\u0438\u0433\u0443\u0440\u043e\u0439 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e, \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>kind<\/code>. \u0412\u043e\u0442 \u043d\u0430\u0448\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>Shape<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">interface Shape {  kind: 'circle' | 'square'  radius?: number  sideLength: number }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 <code>'circle' | 'square'<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>string<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043e\u0440\u0444\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u0448\u0438\u0431\u043e\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function handleShape(shape: Shape) {  \/\/ \u0423\u043f\u0441!  if (shape.kind === 'rect') {    \/\/ This condition will always return 'false' since the types '&quot;circle&quot; | &quot;square&quot;' and '&quot;rect&quot;' have no overlap. \u0414\u0430\u043d\u043d\u043e\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 `false`, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0442\u0438\u043f\u044b '&quot;circle&quot; | &quot;square&quot;' \u0438 '&quot;rect&quot;' \u043d\u0435 \u043f\u0435\u0440\u0435\u0441\u0435\u043a\u0430\u044e\u0442\u0441\u044f    \/\/ ...  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>getArea<\/code> \u0434\u043b\u044f \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043b\u043e\u0449\u0430\u0434\u0438 \u0444\u0438\u0433\u0443\u0440. \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u043a\u0440\u0443\u0433\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getArea(shape: Shape) {  return Math.PI * shape.radius ** 2;  \/\/ Object is possibly 'undefined'. \u041f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f 'undefined' }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u043e\u0439 <code>strictNullChecks<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 <code>radius<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d. \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043f\u0435\u0440\u0435\u0434 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u043a\u043e\u0434\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>kind<\/code>?<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getArea(shape: Shape) {  if (shape.kind === &quot;circle&quot;) {    return Math.PI * shape.radius ** 2;    \/\/ Object is possibly 'undefined'.  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0425\u043c, <code>TS<\/code> \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442, \u0447\u0442\u043e \u0441 \u044d\u0442\u0438\u043c \u0434\u0435\u043b\u0430\u0442\u044c. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043c\u044b \u0437\u043d\u0430\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u0435 (<code>!<\/code> \u043f\u043e\u0441\u043b\u0435 <code>shape.radius<\/code>), \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u043e\u0431\u0449\u0430\u0442\u044c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <code>radius<\/code> \u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u0442\u0438\u043f\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getArea(shape: Shape) {  if (shape.kind === &quot;circle&quot;) {    return Math.PI * shape.radius! ** 2;  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a, \u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b\u043c. \u041c\u044b, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e, \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0433\u043e \u043b\u0443\u0447\u0448\u0435. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043b\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>radius<\/code> \u0438\u043b\u0438 <code>sideLength<\/code> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>kind<\/code>. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 <code>Shape<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">interface Circle {  kind: &quot;circle&quot;;  radius: number; }  interface Square {  kind: &quot;square&quot;;  sideLength: number; }  type Shape = Circle | Square;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b\u0438 <code>Shape<\/code> \u043d\u0430 \u0434\u0432\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>kind<\/code>, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>radius<\/code> \u0438 <code>sideLength<\/code> \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u0438\u043f\u0430\u0445.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443 <code>radius<\/code> \u0442\u0438\u043f\u0430 <code>Shape<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getArea(shape: Shape) {  return Math.PI * shape.radius ** 2;  \/\/ Property 'radius' does not exist on type 'Shape'. Property 'radius' does not exist on type 'Square'. }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0448\u0438\u0431\u043a\u0443. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 <code>TS<\/code> \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <code>shape<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c <code>Square<\/code>, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435\u0442 <code>radius<\/code>. \u0427\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u043d\u043e\u0432\u0430 \u043f\u043e\u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 <code>kind<\/code>?<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getArea(shape: Shape) {  if (shape.kind === &quot;circle&quot;) {    return Math.PI * shape.radius ** 2;                    \/\/ (parameter) shape: Circle  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0431\u0435\u0437 \u043e\u0448\u0438\u0431\u043e\u043a. \u041a\u043e\u0433\u0434\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0438\u043f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u0449\u0435\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0441 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044c\u043d\u044b\u043c \u0442\u0438\u043f\u043e\u043c, <code>TS<\/code> \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u044d\u0442\u043e \u043a\u0430\u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0435\u0435 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0436\u0430\u0442\u044c \u0447\u043b\u0435\u043d\u043e\u0432 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043e\u0431\u0449\u0438\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>kind<\/code> (\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0441\u043e\u0431\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>Shape<\/code>). \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0443\u0436\u0430\u0442\u044c <code>shape<\/code> \u0434\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0435\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>kind<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>'circle'<\/code>, <code>shape<\/code> \u0441\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0434\u043e <code>Circle<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u043e\u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0438 \u0432 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>switch<\/code>. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>getArea<\/code> \u0431\u0435\u0437 <code>!<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getArea(shape: Shape) {  switch (shape.kind) {    case &quot;circle&quot;:      return Math.PI * shape.radius ** 2;                      \/\/ (parameter) shape: Circle    case &quot;square&quot;:      return shape.sideLength ** 2;            \/\/ (parameter) shape: Square  } }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"tip-never\">\u0422\u0438\u043f <code>never<\/code><\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c, \u0432 <code>TS<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u0438\u043f <code>never<\/code>.<\/p>\n<p>  <\/p>\n<h3 id=\"ischerpyvayuschie-proverki-exhaustiveness-checking\">\u0418\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 (exhaustiveness checking)<\/h3>\n<p>  <\/p>\n<p>\u0422\u0438\u043f <code>never<\/code> \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d \u043b\u044e\u0431\u043e\u043c\u0443 \u0442\u0438\u043f\u0443; \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0438\u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d <code>never<\/code> (\u043a\u0440\u043e\u043c\u0435 \u0441\u0430\u043c\u043e\u0433\u043e <code>never<\/code>). \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e <code>never<\/code> \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>switch<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0430\u043a\u043e\u0439 <code>default<\/code> \u0432 <code>getArea<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function getArea(shape: Shape) {  switch (shape.kind) {    case &quot;circle&quot;:      return Math.PI * shape.radius ** 2;    case &quot;square&quot;:      return shape.sideLength ** 2;    default:      const _exhaustiveCheck: never = shape;      return _exhaustiveCheck;  } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0447\u043b\u0435\u043d\u0430 \u0432 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 <code>Shape<\/code> \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u044c \u043a \u043e\u0448\u0438\u0431\u043a\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">interface Triangle {  kind: &quot;triangle&quot;;  sideLength: number; }  type Shape = Circle | Square | Triangle;  function getArea(shape: Shape) {  switch (shape.kind) {    case &quot;circle&quot;:      return Math.PI * shape.radius ** 2;    case &quot;square&quot;:      return shape.sideLength ** 2;    default:      const _exhaustiveCheck: never = shape;      \/\/ Type 'Triangle' is not assignable to type 'never'.      return _exhaustiveCheck;  } }<\/code><\/pre>\n<p>  <\/p>\n<hr>\n<p>  <\/p>\n<p>\u041e\u0431\u043b\u0430\u0447\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b \u043e\u0442 <a href=\"https:\/\/macloud.ru\/?partner=4189mjxpzx\">\u041c\u0430\u043a\u043b\u0430\u0443\u0434<\/a> \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 TypeScript.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0439\u0442\u0435\u0441\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0432\u044b\u0448\u0435 \u0438\u043b\u0438 \u043a\u043b\u0438\u043a\u043d\u0443\u0432 \u043d\u0430 \u0431\u0430\u043d\u043d\u0435\u0440 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0435 10% \u0441\u043a\u0438\u0434\u043a\u0443 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0439 \u043c\u0435\u0441\u044f\u0446 \u0430\u0440\u0435\u043d\u0434\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043b\u044e\u0431\u043e\u0439 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438!<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/macloud.ru\/?partner=4189mjxpzx&amp;utm_source=habr&amp;utm_medium=perevod&amp;utm_campaign=igor\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/et\/1a\/yp\/et1aypandyuamqprsz3m2ntm4ky.png\"><\/a><\/p>\n<\/div>\n<p> \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\/company\/macloud\/blog\/560594\/\"> https:\/\/habr.com\/ru\/company\/macloud\/blog\/560594\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ad\/rw\/w4\/adrww41gv8k_vuxeswr0-xkl57y.png\" alt=\"image\"><\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u043c \u0441\u0435\u0440\u0438\u044e \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0439 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/intro.html\"><code> &quot;\u041a\u0430\u0440\u043c\u0430\u043d\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438 \u043f\u043e TypeScript<\/code>&quot;.<\/a>  <\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u0435 \u0447\u0430\u0441\u0442\u0438:<\/p>\n<p>  <\/p>\n<ul>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/559902\/\">\u0427\u0430\u0441\u0442\u044c 1. \u041e\u0441\u043d\u043e\u0432\u044b<\/a><\/li>\n<li><a href=\"https:\/\/habr.com\/ru\/company\/macloud\/blog\/559976\/\">\u0427\u0430\u0441\u0442\u044c 2. \u0422\u0438\u043f\u044b \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c <code>padLeft<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function padLeft(padding: number | string, input: string): string {  throw new Error('\u0415\u0449\u0435 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e!') }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 <code>padding<\/code> \u2014 \u044d\u0442\u043e <code>number<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u043f\u0435\u0440\u0435\u0434 <code>input<\/code>. \u0415\u0441\u043b\u0438 <code>padding<\/code> \u2014 \u044d\u0442\u043e <code>string<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>padding<\/code> \u043f\u0435\u0440\u0435\u0434 <code>input<\/code>. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443, \u043a\u043e\u0433\u0434\u0430 <code>padLeft<\/code> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <code>number<\/code> \u0434\u043b\u044f <code>padding<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">function padLeft(padding: number | string, input: string): string {  return new Array(padding + 1).join(' ') + input  \/\/ Operator '+' cannot be applied to types 'string | number' and 'number'. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 '+' \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d \u043a \u0442\u0438\u043f\u0430\u043c 'string | number' }<\/code><\/pre>\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-324217","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324217","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=324217"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324217\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}