{"id":343233,"date":"2022-12-27T15:02:56","date_gmt":"2022-12-27T15:02:56","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=343233"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2022-12-27T15:02:56","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=343233","title":{"rendered":"<span>\u0418\u0437\u0443\u0447\u0435\u043d\u0438\u0435 TypeScript \u2014 \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445. \u0427\u0430\u0441\u0442\u044c 3 \u2014 \u041a\u043b\u0430\u0441\u0441\u044b \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041b\u0438\u0445\u043e\u043f\u043e\u0439 \u041a\u0438\u0440\u0438\u043b\u043b, \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e fullstack-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c. \u042d\u0442\u043e &#8212; \u0443\u0436\u0435 \u0442\u0440\u0435\u0442\u044c\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043f\u043e TypeScript \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0442\u0435\u043c\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u044b, \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b.<\/p>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u0438: <br \/><a href=\"https:\/\/habr.com\/ru\/post\/663964\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c 1 &#8212; \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/a> <br \/><a href=\"https:\/\/habr.com\/ru\/post\/664960\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c 2 &#8212; \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<h3>\u041a\u043b\u0430\u0441\u0441\u044b \u0432 TypeScript<\/h3>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435:<\/p>\n<pre><code class=\"typescript\">class Person { name: string; isCool: boolean;     friends: number;      constructor(n: string, c: boolean, f: number) {     this.name = n;     this.isCool = c;     this.friends = f;     }      sayHello() {         return `\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 ${this.name}, \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c ${this.friends} \u0434\u0440\u0443\u0437\u0435\u0439`     } }  const person1 = new Person('\u0414\u0435\u043d\u0438\u0441', false, 10); const person2 = new Person('\u0412\u043e\u0432\u0430', '\u0434\u0430', 6); \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 'string' \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c 'boolean' console.log(person1.sayHello()); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u0435\u043d\u0438\u0441, \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c 10 \u0434\u0440\u0443\u0437\u0435\u0439 <\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 <code>people<\/code> , \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430 <code>Person<\/code> :<\/p>\n<pre><code class=\"typescript\">let People: Person[] = [person1, person2];<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430. TypeScript \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 <code>readonly<\/code> (\u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043d\u0435\u043c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438):<\/p>\n<pre><code class=\"typescript\">class Person { readonly name: string; \/\/ \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u043e - \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c private isCool: boolean; \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 protected email: string; \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0445 \u043e\u0442 \u043d\u0435\u0433\u043e public friends: number; \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u0443\u0433\u043e\u0434\u043d\u043e, \u0434\u0430\u0436\u0435 \u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430        constructor(n: string, c: boolean, e: string, f: number) {     this.name = n;     this.isCool = c;     this.email = e;     this.friends = f;     }      sayMyName() {     console.log(`\u0422\u044b \u043d\u0435 \u0425\u0430\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433, \u0442\u044b ${this.name}`);     } }  const person1 = new Person('\u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432', false, 'men@de.ru', 118); console.log(person.name); \/\/ \u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 person1.name = '\u0425\u0430\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433'; \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f console.log(person1.isCool); \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: private \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e - \u0434\u043e\u0441\u0442\u0443\u043f \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 Person console.log(person1.email); \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: protected \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e - \u0434\u043e\u0441\u0442\u0443\u043f \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 Person \u0438 \u0435\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 console.log(person1.friends); \/\/ public \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e - \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"typescript\">class Person { constructor( readonly name: string, private isCool: boolean, protected email: string, public friends: number ){}        sayMyName() {     console.log(`\u0422\u044b \u043d\u0435 \u0425\u0430\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433, \u0442\u044b ${this.name}`);     } }  const person1 = new Person('\u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432', false, 'men@de.ru', 118); console.log(person.name); \/\/ \u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0441\u043f\u0430\u0441\u0430\u044f \u043d\u0430\u0441 \u043e\u0442 \u0438\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 &#8212; \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0435\u0442 <code>public<\/code>.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c JavaScript:<\/p>\n<pre><code class=\"typescript\">class Programmer extends Person { programmingLanguages: string[];        constructor(     name: string,     isCool: boolean,     email: string,     friends: number,     pL: string[]     ){     \/\/ \u0412\u044b\u0437\u043e\u0432 super \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 (Person), \u0442.\u043a. \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f      super(name, isCool, email, friends);     this.programmingLanguages = pl;     } }<\/code><\/pre>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043e \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/classes.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435 TypeScript<\/a>.<\/p>\n<h3>\u041c\u043e\u0434\u0443\u043b\u0438 \u0432 TypeScript<\/h3>\n<p>\u0412 JavaScript \u043c\u043e\u0434\u0443\u043b\u0438 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0432 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435.<\/p>\n<p>TypeScript \u0442\u0430\u043a \u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0424\u0430\u0439\u043b\u044b TypeScript \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 JavaScript \u0444\u0430\u0439\u043b\u044b.<\/p>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 <code>tsconfig.json<\/code> , \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0430:<\/p>\n<pre><code class=\"json\">\"target\": \"es2016\", \"module\": \"es2015\"<\/code><\/pre>\n<p>(\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0434\u043b\u044f Node-\u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u0430\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>\"module\":\"CommonJS\"<\/code> , \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442.\u043a. Node \u0435\u0449\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0438 \u0438\u043c\u043f\u043e\u0440\u0442.)<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>type=\"module\"<\/code> \u0432 \u0442\u0435\u0433 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0432 \u0432\u0430\u0448\u0435\u043c HTML-\u0444\u0430\u0439\u043b\u0435:<\/p>\n<pre><code class=\"xml\">&lt;script type=\"module\" src=\"\/public\/script.js\">&lt;\/script><\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ES6:<\/p>\n<pre><code class=\"typescript\">\/\/ src\/hello.ts export function sayHi() { console.log('\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!'); }  \/\/ src\/script.ts import { sayHi } from '.\/hello.js'; syaHi(); \/\/ \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c <code>.js<\/code>, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e TypeScript-\u0444\u0430\u0439\u043b.<\/p>\n<h4>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0432 TypeScript<\/h4>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"typescript\">interface Person {   name: string;   age: number; }  function sayHi(person: Person) {   console.log(\u041f\u0440\u0438\u0432\u0435\u0442, ${person.name}); }  sayHi({   name: '\u0414\u0436\u043e\u043d',   age: 33, }); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u0414\u0436\u043e\u043d<\/code><\/pre>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>type<\/code>(\u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c \u0442\u0438\u043f\u0430):<\/p>\n<pre><code class=\"typescript\">type Person = { name: string; age: number; }  function sayHi(person: Person) {     console.log(\u041f\u0440\u0438\u0432\u0435\u0442, ${person.name}); }  sayHi({     name: '\u0414\u0436\u043e\u043d',     age: 33, }); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u0414\u0436\u043e\u043d<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0435 \u0442\u0438\u043f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e, \u043f\u0440\u044f\u043c\u043e \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"typescript\">function sayHi(person: { name: string; age: number }) {     console.log(`\u041f\u0440\u0438\u0432\u0435\u0442, ${person.name}`); }  sayHi({     name: '\u0414\u0436\u043e\u043d',     age: 33, }); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u0414\u0436\u043e\u043d<\/code><\/pre>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b \u0442\u0438\u043f\u043e\u0432, \u0438 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043e\u0431\u043e\u0438\u0445. \u0418\u0445 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 &#8212; \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c, \u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0432\u0437\u044f\u0442\u044b \u0438\u0437 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/everyday-types.html#differences-between-type-aliases-and-interfaces\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 TypeScript<\/a>.<\/p>\n<p>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"typescript\">interface Animal { name: string }  interface Bear extends Animal {   honey: boolean }  const bear: Bear = {   name: '\u0412\u0438\u043d\u043d\u0438',   honey: false, }<\/code><\/pre>\n<p>\u0418\u0437\u0443\u0447\u0435\u043d\u0438\u0435 TypeScript &#8212; \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445. \u0427\u0430\u0441\u0442\u044c 3 &#8212; \u041a\u043b\u0430\u0441\u0441\u044b \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b. \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">type Animal = {   name: string }  type Bear = Animal &amp; {   honey: boolean }  const bear: Bear = {   name: '\u0412\u0438\u043d\u043d\u0438',   honey: true, }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u043a \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443:<\/p>\n<pre><code class=\"typescript\">interface Animal {   name: string }  \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 interface Animal {   tail: boolean }  const dog: Animal = {   name: '\u0425\u0430\u0442\u0438\u043a\u043e',   tail: true, }<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430: \u0442\u0438\u043f\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">type Animal = {   name: string }  type Animal = {   tail: boolean } \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: \u0414\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 'Animal'.<\/code><\/pre>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f TypeScript \u0441\u043e\u0432\u0435\u0442\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442:<\/p>\n<pre><code class=\"typescript\">interface Person { name: string age: number speak(sentence: string): void }  const person1: Person = {   name: '\u0414\u0436\u043e\u043d',   age: 33,   speak: sentence => console.log(sentence), }<\/code><\/pre>\n<p>\u0423 \u0432\u0430\u0441 \u043c\u043e\u0433 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441: \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435?<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 TypeScript, \u043d\u0435 \u0432 JavaScript. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0442\u044c \u043d\u0430\u0448 JavaScript-\u0444\u0430\u0439\u043b. \u0410 \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 JavaScript, \u0442\u043e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043a\u043b\u0430\u0441\u0441 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u0432\u043e\u0435\u0439, <em>\u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/em> (\u0442\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e \u201c\u043f\u043b\u0430\u043d\u201d \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442), \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f <em>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432<\/em>.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u043e\u0447\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442, \u043a\u0430\u043a\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043a\u0430\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442.<\/p>\n<h4>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438<\/h4>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0443, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0443\u0442\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"typescript\">interface HasFormatter { form(): string; }  class Person implements HasFormatter {   constructor(public username: string, protected password: string) {}      format() {   return  this.username.toLocaleLowerCase();   } }  \/\/ \u0414\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 HasFormatter let person1: HasFormatter; let person2: HasFormatter; person1 = new Person('\u0414\u0435\u043d\u0438\u0441', 'password123'); person2 = new Person('\u0416\u0435\u043d\u044f', 'TypeScripter999'); console.log(person1.format()); \/\/ \u0414\u0435\u043d\u0438\u0441<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0442\u0440\u0435\u0442\u044c\u044f \u0447\u0430\u0441\u0442\u044c \u0446\u0438\u043a\u043b\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443, \u0436\u0434\u0443 \u0432\u0430\u0441 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u044f, \u043a\u0430\u043a \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b, \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0438 \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043c.<\/p>\n<p>P.S. \u0410\u0432\u0442\u043e\u0440 \u0438\u0441\u043a\u0440\u0435\u043d\u043d\u0435 \u0438\u0437\u0432\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0435\u0440\u0435\u0440\u044b\u0432 \u043c\u0435\u0436\u0434\u0443 \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u044c\u044e \u0447\u0430\u0441\u0442\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430\u043c\u0438 \u0432 \u0436\u0438\u0437\u043d\u0438 (\u0432 \u0442.\u0447. \u0440\u0435\u043b\u043e\u043a\u0435\u0439\u0442 \u0432 \u041a\u0430\u0437\u0430\u0445\u0441\u0442\u0430\u043d)<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/707990\/\"> https:\/\/habr.com\/ru\/post\/707990\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u041b\u0438\u0445\u043e\u043f\u043e\u0439 \u041a\u0438\u0440\u0438\u043b\u043b, \u044f \u0440\u0430\u0431\u043e\u0442\u0430\u044e fullstack-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c. \u042d\u0442\u043e &#8212; \u0443\u0436\u0435 \u0442\u0440\u0435\u0442\u044c\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u0430 \u043f\u043e TypeScript \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0442\u0435\u043c\u044b, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u044b, \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b.<\/p>\n<p>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0447\u0430\u0441\u0442\u0438: <br \/><a href=\"https:\/\/habr.com\/ru\/post\/663964\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c 1 &#8212; \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0438 \u043f\u0440\u0438\u043c\u0438\u0442\u0438\u0432\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/a> <br \/><a href=\"https:\/\/habr.com\/ru\/post\/664960\/\" rel=\"noopener noreferrer nofollow\">\u0427\u0430\u0441\u0442\u044c 2 &#8212; \u0441\u0441\u044b\u043b\u043e\u0447\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445<\/a><\/p>\n<h3>\u041a\u043b\u0430\u0441\u0441\u044b \u0432 TypeScript<\/h3>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043b\u044e\u0431\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435:<\/p>\n<pre><code class=\"typescript\">class Person { name: string; isCool: boolean;     friends: number;      constructor(n: string, c: boolean, f: number) {     this.name = n;     this.isCool = c;     this.friends = f;     }      sayHello() {         return `\u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 ${this.name}, \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c ${this.friends} \u0434\u0440\u0443\u0437\u0435\u0439`     } }  const person1 = new Person('\u0414\u0435\u043d\u0438\u0441', false, 10); const person2 = new Person('\u0412\u043e\u0432\u0430', '\u0434\u0430', 6); \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0442\u0438\u043f\u0430 'string' \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0443 \u0441 \u0442\u0438\u043f\u043e\u043c 'boolean' console.log(person1.sayHello()); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u043c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u0435\u043d\u0438\u0441, \u0443 \u043c\u0435\u043d\u044f \u0435\u0441\u0442\u044c 10 \u0434\u0440\u0443\u0437\u0435\u0439 <\/code><\/pre>\n<p>\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 <code>people<\/code> , \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043a\u043b\u0430\u0441\u0441\u0430 <code>Person<\/code> :<\/p>\n<pre><code class=\"typescript\">let People: Person[] = [person1, person2];<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430. TypeScript \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 <code>readonly<\/code> (\u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043d\u0435\u043c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0447\u0430\u0441\u0442\u0438):<\/p>\n<pre><code class=\"typescript\">class Person { readonly name: string; \/\/ \u044d\u0442\u043e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u043e - \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c private isCool: boolean; \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 protected email: string; \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437 \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u044b\u0445 \u043e\u0442 \u043d\u0435\u0433\u043e public friends: number; \/\/ \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0442\u043a\u0443\u0434\u0430 \u0443\u0433\u043e\u0434\u043d\u043e, \u0434\u0430\u0436\u0435 \u0432\u043d\u0435 \u043a\u043b\u0430\u0441\u0441\u0430        constructor(n: string, c: boolean, e: string, f: number) {     this.name = n;     this.isCool = c;     this.email = e;     this.friends = f;     }      sayMyName() {     console.log(`\u0422\u044b \u043d\u0435 \u0425\u0430\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433, \u0442\u044b ${this.name}`);     } }  const person1 = new Person('\u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432', false, 'men@de.ru', 118); console.log(person.name); \/\/ \u0432\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 person1.name = '\u0425\u0430\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433'; \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f console.log(person1.isCool); \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: private \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e - \u0434\u043e\u0441\u0442\u0443\u043f \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 Person console.log(person1.email); \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: protected \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e - \u0434\u043e\u0441\u0442\u0443\u043f \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 Person \u0438 \u0435\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u0445 console.log(person1.friends); \/\/ public \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e - \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/code><\/pre>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0431\u043e\u043b\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c, \u0435\u0441\u043b\u0438 \u043e\u043f\u0438\u0448\u0435\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043a\u043b\u0430\u0441\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"typescript\">class Person { constructor( readonly name: string, private isCool: boolean, protected email: string, public friends: number ){}        sayMyName() {     console.log(`\u0422\u044b \u043d\u0435 \u0425\u0430\u0439\u0437\u0435\u043d\u0431\u0435\u0440\u0433, \u0442\u044b ${this.name}`);     } }  const person1 = new Person('\u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432', false, 'men@de.ru', 118); console.log(person.name); \/\/ \u041c\u0435\u043d\u0434\u0435\u043b\u0435\u0435\u0432<\/code><\/pre>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u044f\u043c\u043e \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435, \u0441\u043f\u0430\u0441\u0430\u044f \u043d\u0430\u0441 \u043e\u0442 \u0438\u0445 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 &#8212; \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0443\u043f\u0430, \u0442\u043e \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0435\u0442 <code>public<\/code>.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0433\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c JavaScript:<\/p>\n<pre><code class=\"typescript\">class Programmer extends Person { programmingLanguages: string[];        constructor(     name: string,     isCool: boolean,     email: string,     friends: number,     pL: string[]     ){     \/\/ \u0412\u044b\u0437\u043e\u0432 super \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 (Person), \u0442.\u043a. \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043d\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f      super(name, isCool, email, friends);     this.programmingLanguages = pl;     } }<\/code><\/pre>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043e \u043a\u043b\u0430\u0441\u0441\u0430\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u043d\u0430 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/classes.html\" rel=\"noopener noreferrer nofollow\">\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435 TypeScript<\/a>.<\/p>\n<h3>\u041c\u043e\u0434\u0443\u043b\u0438 \u0432 TypeScript<\/h3>\n<p>\u0412 JavaScript \u043c\u043e\u0434\u0443\u043b\u0438 &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0444\u0430\u0439\u043b\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434. \u0424\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u043a\u043e\u0434 \u0432 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435.<\/p>\n<p>TypeScript \u0442\u0430\u043a \u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u043e\u0434\u0443\u043b\u0435\u0439. \u0424\u0430\u0439\u043b\u044b TypeScript \u0431\u0443\u0434\u0443\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 JavaScript \u0444\u0430\u0439\u043b\u044b.<\/p>\n<p>\u0418\u0437\u043c\u0435\u043d\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u0444\u0430\u0439\u043b\u0435 <code>tsconfig.json<\/code> , \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0430 \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0430:<\/p>\n<pre><code class=\"json\">\"target\": \"es2016\", \"module\": \"es2015\"<\/code><\/pre>\n<p>(\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0434\u043b\u044f Node-\u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0432\u0430\u043c, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>\"module\":\"CommonJS\"<\/code> , \u044d\u0442\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u0442.\u043a. Node \u0435\u0449\u0435 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u0438 \u0438\u043c\u043f\u043e\u0440\u0442.)<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 <code>type=\"module\"<\/code> \u0432 \u0442\u0435\u0433 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0432 \u0432\u0430\u0448\u0435\u043c HTML-\u0444\u0430\u0439\u043b\u0435:<\/p>\n<pre><code class=\"xml\">&lt;script type=\"module\" src=\"\/public\/script.js\">&lt;\/script><\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e ES6:<\/p>\n<pre><code class=\"typescript\">\/\/ src\/hello.ts export function sayHi() { console.log('\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!'); }  \/\/ src\/script.ts import { sayHi } from '.\/hello.js'; syaHi(); \/\/ \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/code><\/pre>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435: \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0444\u0430\u0439\u043b \u0441 \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c <code>.js<\/code>, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u044d\u0442\u043e TypeScript-\u0444\u0430\u0439\u043b.<\/p>\n<h4>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0432 TypeScript<\/h4>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"typescript\">interface Person {   name: string;   age: number; }  function sayHi(person: Person) {   console.log(\u041f\u0440\u0438\u0432\u0435\u0442, ${person.name}); }  sayHi({   name: '\u0414\u0436\u043e\u043d',   age: 33, }); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u0414\u0436\u043e\u043d<\/code><\/pre>\n<p>\u0412\u044b \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <code>type<\/code>(\u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c \u0442\u0438\u043f\u0430):<\/p>\n<pre><code class=\"typescript\">type Person = { name: string; age: number; }  function sayHi(person: Person) {     console.log(\u041f\u0440\u0438\u0432\u0435\u0442, ${person.name}); }  sayHi({     name: '\u0414\u0436\u043e\u043d',     age: 33, }); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u0414\u0436\u043e\u043d<\/code><\/pre>\n<p>\u0410 \u0435\u0449\u0435 \u0442\u0438\u043f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u043a\u0430\u0437\u0430\u043d \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e, \u043f\u0440\u044f\u043c\u043e \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438:<\/p>\n<pre><code class=\"typescript\">function sayHi(person: { name: string; age: number }) {     console.log(`\u041f\u0440\u0438\u0432\u0435\u0442, ${person.name}`); }  sayHi({     name: '\u0414\u0436\u043e\u043d',     age: 33, }); \/\/ \u041f\u0440\u0438\u0432\u0435\u0442, \u0414\u0436\u043e\u043d<\/code><\/pre>\n<p>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b \u0442\u0438\u043f\u043e\u0432, \u0438 \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043e\u0431\u043e\u0438\u0445. \u0418\u0445 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0435 &#8212; \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u044b \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c, \u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043c\u043e\u0436\u043d\u043e.<\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0432\u0437\u044f\u0442\u044b \u0438\u0437 <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/2\/everyday-types.html#differences-between-type-aliases-and-interfaces\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 TypeScript<\/a>.<\/p>\n<p>\u041d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"typescript\">interface Animal { name: string }  interface Bear extends Animal {   honey: boolean }  const bear: Bear = {   name: '\u0412\u0438\u043d\u043d\u0438',   honey: false, }<\/code><\/pre>\n<p>\u0418\u0437\u0443\u0447\u0435\u043d\u0438\u0435 TypeScript &#8212; \u043f\u043e\u043b\u043d\u043e\u0435 \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u0434\u043b\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0445. \u0427\u0430\u0441\u0442\u044c 3 &#8212; \u041a\u043b\u0430\u0441\u0441\u044b \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b. \u0442\u0438\u043f\u043e\u0432:<\/p>\n<pre><code class=\"typescript\">type Animal = {   name: string }  type Bear = Animal &amp; {   honey: boolean }  const bear: Bear = {   name: '\u0412\u0438\u043d\u043d\u0438',   honey: true, }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u043a \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443:<\/p>\n<pre><code class=\"typescript\">interface Animal {   name: string }  \/\/ \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 interface Animal {   tail: boolean }  const dog: Animal = {   name: '\u0425\u0430\u0442\u0438\u043a\u043e',   tail: true, }<\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0438 \u0440\u0430\u0437\u043d\u0438\u0446\u0430: \u0442\u0438\u043f\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"typescript\">type Animal = {   name: string }  type Animal = {   tail: boolean } \/\/ \u041e\u0428\u0418\u0411\u041a\u0410: \u0414\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0439\u0441\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 'Animal'.<\/code><\/pre>\n<p>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f TypeScript \u0441\u043e\u0432\u0435\u0442\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442:<\/p>\n<pre><code class=\"typescript\">interface Person { name: string age: number speak(sentence: string): void }  const person1: Person = {   name: '\u0414\u0436\u043e\u043d',   age: 33,   speak: sentence => console.log(sentence), }<\/code><\/pre>\n<p>\u0423 \u0432\u0430\u0441 \u043c\u043e\u0433 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441: \u043f\u043e\u0447\u0435\u043c\u0443 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435?<\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 TypeScript, \u043d\u0435 \u0432 JavaScript. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043e\u043d\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b, \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u0434\u0443\u0432\u0430\u0442\u044c \u043d\u0430\u0448 JavaScript-\u0444\u0430\u0439\u043b. \u0410 \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0432 JavaScript, \u0442\u043e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u044b.<\/p>\n<p>\u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043a\u043b\u0430\u0441\u0441 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u0432\u043e\u0435\u0439, <em>\u0444\u0430\u0431\u0440\u0438\u043a\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/em> (\u0442\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e \u201c\u043f\u043b\u0430\u043d\u201d \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442), \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f <em>\u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0442\u0438\u043f\u043e\u0432<\/em>.<\/p>\n<p>\u041a\u043b\u0430\u0441\u0441 \u043c\u043e\u0436\u0435\u0442 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043c\u043e\u0447\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442, \u043a\u0430\u043a\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043a\u0430\u043a\u0438\u0445 \u0442\u0438\u043f\u043e\u0432 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442.<\/p>\n<h4>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u0441 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438<\/h4>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u0443, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u0443\u0442\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<pre><code class=\"typescript\">interface HasFormatter { form(): string; }  class Person implements HasFormatter {   constructor(public username: string, protected password: string) {}      format() {   return  this.username.toLocaleLowerCase();   } }  \/\/ \u0414\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 HasFormatter let person1: HasFormatter; let person2: HasFormatter; person1 = new Person('\u0414\u0435\u043d\u0438\u0441', 'password123'); person2 = new Person('\u0416\u0435\u043d\u044f', 'TypeScripter999'); console.log(person1.format()); \/\/ \u0414\u0435\u043d\u0438\u0441<\/code><\/pre>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u0442\u0440\u0435\u0442\u044c\u044f \u0447\u0430\u0441\u0442\u044c \u0446\u0438\u043a\u043b\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443, \u0436\u0434\u0443 \u0432\u0430\u0441 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u044b \u0442\u0430\u043a\u0438\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u044f, \u043a\u0430\u043a \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b, \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u0438 \u0438 \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0435\u043c.<\/p>\n<p>P.S. \u0410\u0432\u0442\u043e\u0440 \u0438\u0441\u043a\u0440\u0435\u043d\u043d\u0435 \u0438\u0437\u0432\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0435\u0440\u0435\u0440\u044b\u0432 \u043c\u0435\u0436\u0434\u0443 \u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u044c\u044e \u0447\u0430\u0441\u0442\u044f\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u0430\u043c\u0438 \u0432 \u0436\u0438\u0437\u043d\u0438 (\u0432 \u0442.\u0447. \u0440\u0435\u043b\u043e\u043a\u0435\u0439\u0442 \u0432 \u041a\u0430\u0437\u0430\u0445\u0441\u0442\u0430\u043d)<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/707990\/\"> https:\/\/habr.com\/ru\/post\/707990\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-343233","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343233","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=343233"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/343233\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}