{"id":297341,"date":"2020-01-19T15:00:17","date_gmt":"2020-01-19T15:00:17","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297341"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297341","title":{"rendered":"10 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0441\u043e\u0431\u0435\u0441\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u043e TypeScript (\u0441 \u043a\u0440\u0430\u0442\u043a\u0438\u043c\u0438 \u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438)"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484546\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nf\/hx\/m-\/nfhxm-chhj1dh0jgxvcnh6374po.png\"><\/p>\n<p>  <\/p>\n<p><strong>1. \u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u0442\u0438\u043f \u00abOmit\u00bb?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u042d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">type Person = { name: string; age: number; location: string; }; type QuantumPerson = Omit&lt;Person, 'location'&gt;; \/\/ \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 QuantumPerson = { name: string; age: number; };<\/code><\/pre>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p><strong>2. \u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u00abdeclare\u00bb?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 JavaScript, \u043d\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0432 \u0432\u0430\u0448\u0435\u043c TypeScript \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: <\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">declare const libraryName; <\/code><\/pre>\n<p>  <\/p>\n<p><strong>3. \u041a\u0430\u043a \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u044b declaration?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043e\u043f\u0446\u0438\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 \u043d\u0430 <em>true<\/em> \u0432 \u0444\u0430\u0439\u043b\u0435 <em>tsconfig.json<\/em><\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">{ &quot;compilerOptions&quot;: {     ...     &quot;declaration&quot;: true,   } } <\/code><\/pre>\n<p>  <\/p>\n<p><strong>4. \u041a\u0430\u043a \u043f\u0440\u0435\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u041d\u0430\u0434\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e \u0436\u0435 \u0438\u043c\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u0434 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0431\u0435\u0437 \u0441\u043a\u043e\u0431\u043e\u043a {} \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0438 \u0442\u0438\u043f\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438\/\u0438\u043b\u0438 \u0442\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function add(x: string, y: string): string; function add(x: number, y: number): number {   return x + y; } <\/code><\/pre>\n<p>  <\/p>\n<p><strong>5. \u041a\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0435\u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0442\u0438\u043f <em>Partial<\/em><\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">interface Person {   name: string;   age: number; }  type PartialPerson = Partial&lt;Person&gt;; \/\/ \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u043a\u043e\u0434\u0443  linesinterface PartialPerson {   name?: string;   age?: number; }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>6. \u041a \u0447\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u044b?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u041a\u043b\u0430\u0441\u0441\u044b, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">@MyClassDecorator export class Person {      \u2026     @MyPropertyDecorator myProperty: string; }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>7. \u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u0442\u0438\u043f \u00abRecord\u00bb?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u043c\u0430\u043f\u0443<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let Person = Record&lt;string, number&gt; = {}; Person.age = 25;<\/code><\/pre>\n<p>  <\/p>\n<p><strong>8. \u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043b\u0430\u0441\u0441\u0430\u043c \u0432\u043d\u0435 \u043c\u043e\u0434\u0443\u043b\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <em>export<\/em> \u043f\u0435\u0440\u0435\u0434 \u0438\u043c\u0435\u043d\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>: <\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">export class Person {}<\/code><\/pre>\n<p>  <\/p>\n<p><strong>9. \u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u00abunknown\u00bb?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u041a\u043e\u0433\u0434\u0430 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <em>any<\/em> \u0438\/\u0438\u043b\u0438 \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442\u0435 \u0442\u043e\u0447\u043d\u044b\u0439 \u0442\u0438\u043f, \u043d\u043e \u0445\u043e\u0442\u0438\u0442\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">let person: unknown = 'John'; if (typeof person === string) {   let name: string = person; } <\/code><\/pre>\n<p>  <\/p>\n<p><strong>10. \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u00ab.map\u00bb \u0444\u0430\u0439\u043b, \u043a\u0430\u043a \u0438 \u0437\u0430\u0447\u0435\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: <em>Map<\/em>-\u0444\u0430\u0439\u043b \u2014 \u044d\u0442\u043e \u0444\u0430\u0439\u043b \u043a\u0430\u0440\u0442\u044b \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0438. \u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0432 \u043e\u043f\u0446\u0438\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430 <em>sourceMap<\/em> \u0432 <em>true<\/em> \u0432 \u0444\u0430\u0439\u043b\u0435 <em>tsconfig.json<\/em><\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">{ &quot;compilerOptions&quot;: {     ...     &quot;sourceMap&quot;: true,   } } <\/code><\/pre>\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\/post\/484546\/\"> https:\/\/habr.com\/ru\/post\/484546\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484546\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/nf\/hx\/m-\/nfhxm-chhj1dh0jgxvcnh6374po.png\"><\/p>\n<p>  <\/p>\n<p><strong>1. \u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u0442\u0438\u043f \u00abOmit\u00bb?<\/strong><\/p>\n<p>  <\/p>\n<p><strong>\u041e\u0442\u0432\u0435\u0442<\/strong>: \u042d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0442\u0438\u043f, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440<\/strong>:<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">type Person = { name: string; age: number; location: string; }; type QuantumPerson = Omit&lt;Person, 'location'&gt;; \/\/ \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 QuantumPerson = { name: string; age: 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-297341","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297341","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=297341"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297341\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}