{"id":297299,"date":"2020-01-17T21:00:23","date_gmt":"2020-01-17T21:00:23","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=297299"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=297299","title":{"rendered":"\u0427\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f TypeScript \u2014 \u0427\u0430\u0441\u0442\u044c 1"},"content":{"rendered":"\n<div class=\"post__text post__text-html\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/484402\/\">\n<p>\u041d\u0430\u0442\u043a\u043d\u0443\u0432\u0448\u0438\u0441\u044c \u043d\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c \u0447\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f <a href=\"https:\/\/github.com\/labs42io\/clean-code-typescript\">TypeScript<\/a> \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u0435\u0433\u043e \u0440\u0435\u0448\u0438\u043b \u0432\u0437\u044f\u0442\u044c\u0441\u044f \u0437\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434. \u0417\u0434\u0435\u0441\u044c \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u044b\u0434\u0435\u0440\u0436\u043a\u0430\u043c\u0438 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f TypeScript \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0434\u043b\u044f JavaScript, \u044f \u0438\u0445 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0434\u043b\u044f JS \u0443\u0436\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u0445\u0430\u0431\u0440\u0435(@<a href=\"https:\/\/habr.com\/users\/BoryaMogila\/\">BoryaMogila<\/a>) \u0438\u043b\u0438 \u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 \u043d\u0438\u043c\u0438 \u0432 <a href=\"https:\/\/github.com\/ryanmcdermott\/clean-code-javascript\">\u043f\u0435\u0440\u0432\u043e\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vd\/jq\/zm\/vdjqzmfyud98puvitjt3c4-xftu.jpeg\"\/><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0436\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c\u0441\u044f \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435, \u044d\u0442\u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u041d\u043e \u0434\u0430\u0442\u044c \u0447\u0435\u0442\u043a\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e \u0432\u0440\u044f\u0434 \u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u041e\u0442\u0447\u0430\u0441\u0442\u0438 \u044d\u0442\u043e \u0432\u0441\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u043b\u044e\u0434\u0435\u0439, \u0442\u0430\u043a \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0448\u044c \u0432 \u043c\u0443\u0437\u0435\u0439 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0448\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u0438 \u0434\u0443\u043c\u0430\u0435\u0448\u044c \u0447\u0442\u043e \u0437\u0430 \u0443\u0440\u043e\u0434\u0441\u0442\u0432\u043e, \u043d\u043e \u0442\u0443\u0442 \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u0447\u0435\u043b\u043e\u0432\u0435\u043a \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442, \u043a\u0430\u043a\u043e\u0435 \u0432\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u0438\u0435. \u0414\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435, \u043e\u0431\u0449\u0438\u0435 \u0447\u0435\u0440\u0442\u044b \u043c\u0438\u0440\u0430, \u0433\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0442\u043e \u0438\u043b\u0438 \u0438\u043d\u043e\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u043d\u043e \u0434\u0430\u0442\u044c \u0432\u0441\u0435\u043c\u0443 \u044d\u0442\u043e\u043c\u0443 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u044b \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c. \u0422\u0430\u043a \u0438 \u0437\u0434\u0435\u0441\u044c \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043a\u0430\u043a\u0438\u0435 \u0442\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043a\u0440\u0438\u0442\u0435\u0440\u0438\u0438 \u044d\u0442\u043e\u0439 \u043a\u0440\u0430\u0441\u043e\u0442\u044b, \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u0442 \u0441\u0430\u043c, \u0442\u0430\u043a \u043a\u0430\u043a. \u044d\u0442\u043e \u043d\u0435 \u0442\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0441\u0435\u0447\u0435\u043d\u044b \u0432 \u0433\u0440\u0430\u043d\u0438\u0442\u0435. \u042d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<h1 id=\"peremennye\">\u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435<\/h1>\n<p>  <\/p>\n<h2 id=\"ispolzuyte-enum-dlya-dokumentirovaniya\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 enum \u0434\u043b\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>  <\/p>\n<p>Enam&#8217;\u044b \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u0431\u0435\u0441\u043f\u043e\u043a\u043e\u0435\u043d\u044b \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u043b\u043e\u0445\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">const GENRE = {   ROMANTIC: 'romantic',   DRAMA: 'drama',   COMEDY: 'comedy',   DOCUMENTARY: 'documentary', }  projector.configureFilm(GENRE.COMEDY);  class Projector {   \/\/ delactation of Projector   configureFilm(genre) {     switch (genre) {       case GENRE.ROMANTIC:         \/\/ some logic to be executed      }   } }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">enum GENRE {   ROMANTIC,   DRAMA,   COMEDY,   DOCUMENTARY, }  projector.configureFilm(GENRE.COMEDY);  class Projector {   \/\/ delactation of Projector   configureFilm(genre) {     switch (genre) {       case GENRE.ROMANTIC:         \/\/ some logic to be executed      }   } }<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"funkcii\">\u0424\u0443\u043d\u043a\u0446\u0438\u0438<\/h1>\n<p>  <\/p>\n<h2 id=\"izbegayte-proverki-tipov\">\u0418\u0437\u0431\u0435\u0433\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432<\/h2>\n<p>  <\/p>\n<p>TypeScript \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0434\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 JavaScript \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f \u044f\u0437\u044b\u043a\u0430. \u0412\u0441\u0435\u0433\u0434\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0441\u044e \u043c\u043e\u0449\u044c TypeScript. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0431\u0443\u0434\u0443\u0449\u0438\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433 \u0431\u043e\u043b\u0435\u0435 \u043b\u0435\u0433\u043a\u0438\u043c.<\/p>\n<p>  <\/p>\n<p><strong>\u041f\u043b\u043e\u0445\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function travelToTexas(vehicle: Bicycle | Car) {   if (vehicle instanceof Bicycle) {     vehicle.pedal(currentLocation, new Location('texas'));   } else if (vehicle instanceof Car) {     vehicle.drive(currentLocation, new Location('texas'));   } }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">type Vehicle = Bicycle | Car;  function travelToTexas(vehicle: Vehicle) {   vehicle.move(currentLocation, new Location('texas')); }<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"ispolzuyte-iteratory-i-generatory\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b<\/h2>\n<p>  <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u043e\u0442\u043e\u043a.<br \/>  \u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u0447\u0438\u043d \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u043e\u0442\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0432 \u0442\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435, \u0447\u0442\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0440\u0435\u0448\u0430\u0435\u0442 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432<br \/>  \u0438\u043c\u0435\u0442\u044c \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430<\/li>\n<li>\u043b\u0435\u043d\u0438\u0432\u043e\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435, \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u043e \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044e<\/li>\n<li>\u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0430 <code>for-of<\/code><\/li>\n<li>\u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u043e\u0432<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u043b\u043e\u0445\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">function fibonacci(n: number): number[] {   if (n === 1) return [0];   if (n === 2) return [0, 1];    const items: number[] = [0, 1];   while (items.length &lt; n) {     items.push(items[items.length - 2] + items[items.length - 1]);   }    return items; }  function print(n: number) {   fibonacci(n).forEach(fib =&gt; console.log(fib)); }  \/\/ Print first 10 Fibonacci numbers. print(10);<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">\/\/ Generates an infinite stream of Fibonacci numbers. \/\/ The generator doesn't keep the array of all numbers. function* fibonacci(): IterableIterator&lt;number&gt; {   let [a, b] = [0, 1];    while (true) {     yield a;     [a, b] = [b, a + b];   } }  function print(n: number) {   let i = 0;   for (const fib of fibonacci()) {     if (i++ === n) break;       console.log(fib);   }   }  \/\/ Print first 10 Fibonacci numbers. print(10);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438, \u043f\u0443\u0442\u0435\u043c \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0442\u0430\u043a\u0438\u0445 \u043a\u0430\u043a <code>map<\/code>, <code>slice<\/code>, <code>forEach<\/code> \u0438 \u0434\u0440. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 <a href=\"https:\/\/www.npmjs.com\/package\/itiriri\">itiriri<\/a> \u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438 (\u0438\u043b\u0438 <a href=\"https:\/\/www.npmjs.com\/package\/itiriri-async\">itiriri-async<\/a> \u0434\u043b\u044f \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0438 \u0441 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u0430\u043c\u0438).<\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">import itiriri from 'itiriri';  function* fibonacci(): IterableIterator&lt;number&gt; {   let [a, b] = [0, 1];    while (true) {     yield a;     [a, b] = [b, a + b];   } }  itiriri(fibonacci())   .take(10)   .forEach(fib =&gt; console.log(fib));<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"obekty-i-struktury-dannyh\">\u041e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/h1>\n<p>  <\/p>\n<h2 id=\"ispolzuyte-gettery-i-settery\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u044b<\/h2>\n<p>  <\/p>\n<p>TypeScript \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432 \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u0435\u0442\u0442\u0435\u0440\u044b \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u044b \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0435\u0433\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c. &quot;\u041f\u043e\u0447\u0435\u043c\u0443?&quot; \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b. \u0412\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u0440\u0438\u0447\u0438\u043d:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0443, \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0430 \u043d\u0435 \u043f\u043e \u0432\u0441\u0435\u043c\u0443 \u043a\u043e\u0434\u0443<\/li>\n<li>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u043b\u0435\u0433\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>set<\/code><\/li>\n<li>\u0418\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u044f\u0446\u0438\u044f \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/li>\n<li>\u041b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0433\u0435\u0442\u0442\u0435\u0440\u043e\u0432 \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u043e\u0432<\/li>\n<li>\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0435\u043d\u0438\u0432\u043e \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/li>\n<\/ul>\n<p>  <\/p>\n<p><strong>\u041f\u043b\u043e\u0445\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">type BankAccount = {   balance: number;   \/\/ ... }  const value = 100; const account: BankAccount = {   balance: 0,   \/\/ ... };  if (value &lt; 0) {   throw new Error('Cannot set negative balance.'); }  account.balance = value;<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">class BankAccount {   private accountBalance: number = 0;    get balance(): number {     return this.accountBalance;   }    set balance(value: number) {     if (value &lt; 0) {       throw new Error('Cannot set negative balance.');     }      this.accountBalance = value;   }    \/\/ ... }  \/\/ \u0422\u0435\u043f\u0435\u0440\u044c `BankAccount` \u0438\u043d\u043a\u0430\u043f\u0441\u0443\u043b\u0438\u0440\u0443\u0435\u0442 \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438. \/\/ \u0415\u0441\u043b\u0438 \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u0441\u044f, \u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438, \/\/ \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e `\u0441\u0435\u0442\u0442\u0435\u0440\u0430`, \/\/ \u043e\u0441\u0442\u0430\u0432\u0438\u0432 \u0432\u0435\u0441\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043a\u043e\u0434 \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439. const account = new BankAccount(); account.balance = 100;<\/code><\/pre>\n<p>  <\/p>\n<h2 id=\"sozdavayte-obekty-s-privatnymizaschischennymi-polyami\">\u0421\u043e\u0437\u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c\u0438\/\u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438<\/h2>\n<p>  <\/p>\n<p>TypeScript \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 <code>public<\/code> <em>(\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e)<\/em>, <code>protected<\/code> \u0438 <code>private<\/code> \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430. <\/p>\n<p>  <\/p>\n<p><strong>\u041f\u043b\u043e\u0445\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">class Circle {   radius: number;    constructor(radius: number) {     this.radius = radius;   }    perimeter() {     return 2 * Math.PI * this.radius;   }    surface() {     return Math.PI * this.radius * this.radius;   } }<\/code><\/pre>\n<p>  <\/p>\n<p><strong>\u0425\u043e\u0440\u043e\u0448\u043e:<\/strong><\/p>\n<p>  <\/p>\n<pre><code class=\"javascript\">class Circle {   constructor(private readonly radius: number) {   }    perimeter() {     return 2 * Math.PI * this.radius;   }    surface() {     return Math.PI * this.radius * this.radius;   } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423\u0432\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0438, \u0430 \u043a\u0430\u043a\u0438\u043c\u0438 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c\u0438 \u0432\u044b \u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435\u0441\u044c \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 TypeScript?<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442&#8230;<\/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\/post\/484402\/\"> https:\/\/habr.com\/ru\/post\/484402\/<\/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\/484402\/\">\n<p>\u041d\u0430\u0442\u043a\u043d\u0443\u0432\u0448\u0438\u0441\u044c \u043d\u0430 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0430\u043c \u0447\u0438\u0441\u0442\u044b\u0439 \u043a\u043e\u0434 \u0434\u043b\u044f <a href=\"https:\/\/github.com\/labs42io\/clean-code-typescript\">TypeScript<\/a> \u0438 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0432 \u0435\u0433\u043e \u0440\u0435\u0448\u0438\u043b \u0432\u0437\u044f\u0442\u044c\u0441\u044f \u0437\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434. \u0417\u0434\u0435\u0441\u044c \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0432\u044b\u0434\u0435\u0440\u0436\u043a\u0430\u043c\u0438 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0447\u0438\u0441\u0442\u043e\u0433\u043e \u043a\u043e\u0434\u0430 \u0434\u043b\u044f TypeScript \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0442 \u0442\u0430\u043a\u0438\u0435 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u044b \u0434\u043b\u044f JavaScript, \u044f \u0438\u0445 \u0437\u0434\u0435\u0441\u044c \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0443, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0434\u043b\u044f JS \u0443\u0436\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043b\u0441\u044f \u043d\u0430 \u0445\u0430\u0431\u0440\u0435(@<a href=\"https:\/\/habr.com\/users\/BoryaMogila\/\">BoryaMogila<\/a>) \u0438\u043b\u0438 \u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 \u043d\u0438\u043c\u0438 \u0432 <a href=\"https:\/\/github.com\/ryanmcdermott\/clean-code-javascript\">\u043f\u0435\u0440\u0432\u043e\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0435<\/a>.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vd\/jq\/zm\/vdjqzmfyud98puvitjt3c4-xftu.jpeg\"\/><\/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-297299","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297299","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=297299"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/297299\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}