Mercurial > hg > nginx-site
annotate xml/ru/docs/njs/typescript.xml @ 2675:893cd7724c8c
Documented the "r" argument for js_body_filter.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Tue, 09 Mar 2021 18:44:56 +0000 |
parents | 0e6bbd8138c4 |
children | ff357b676c2e |
rev | line source |
---|---|
2541
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
1 <?xml version="1.0"?> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
2 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
3 <!-- |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
4 Copyright (C) Nginx, Inc. |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
5 --> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
6 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
8 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
9 <article name="Создание кода njs при помощи файлов деклараций TypeScript" |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
10 link="/en/docs/njs/typescript.html" |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
11 lang="en" |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
12 rev="1"> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
13 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
14 <section> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
15 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
16 <para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
17 <link url="https://www.typescriptlang.org">TypeScript</link>—это |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
18 типизированное подмножество JavaScript, |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
19 которое компилируется в обычный JavaScript. |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
20 </para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
21 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
22 <para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
23 TypeScript поддерживает файлы деклараций, в которых содержится |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
24 типизированная информация существующих библиотек JavaScript. |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
25 С их помощью программы могут использовать значения в файлах также, |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
26 если бы эти значения были статически типизированными сущностями TypeScript. |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
27 </para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
28 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
29 <para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
30 В njs файлы деклараций TypeScript предоставляются для |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
31 <link doc="reference.xml">API</link> и могут использоваться при: |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
32 <list type="bullet"> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
33 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
34 <listitem> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
35 автозаполнении и проверки API в редакторе |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
36 </listitem> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
37 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
38 <listitem> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
39 создании типобезопасного njs-кода. |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
40 </listitem> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
41 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
42 </list> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
43 </para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
44 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
45 </section> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
46 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
47 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
48 <section id="get" name="Компиляция файлов деклараций TypeScript"> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
49 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
50 <para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
51 <example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
52 $ hg clone http://hg.nginx.org/njs |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
53 $ cd njs && ./configure && make ts |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
54 $ ls build/ts/ |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
55 njs_core.d.ts |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
56 njs_shell.d.ts |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
57 ngx_http_js_module.d.ts |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
58 ngx_stream_js_module.d.ts |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
59 </example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
60 </para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
61 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
62 </section> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
63 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
64 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
65 <section id="autocomplete" name="Проверка API и автозаполнение"> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
66 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
67 <para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
68 Файлы деклараций <literal>*.d.ts</literal> необходимо поместить в место, |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
69 доступное редактору: |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
70 </para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
71 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
72 <para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
73 <literal>test.js</literal>: |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
74 <example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
75 /// <reference path="ngx_http_js_module.d.ts" /> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
76 /** |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
77 * @param {NginxHTTPRequest} r |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
78 * */ |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
79 function content_handler(r) { |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
80 r.headersOut['content-type'] = 'text/plain'; |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
81 r.return(200, "Hello"); |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
82 } |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
83 </example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
84 </para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
85 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
86 </section> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
87 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
88 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
89 <section id="write" name="Создание типобезопасного njs кода"> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
90 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
91 <para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
92 <literal>test.ts</literal>: |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
93 <example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
94 /// <reference path="ngx_http_js_module.d.ts" /> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
95 function content_handler(r: NginxHTTPRequest) { |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
96 r.headersOut['content-type'] = 'text/plain'; |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
97 r.return(200, "Hello from TypeScript"); |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
98 } |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
99 </example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
100 Установка TypeScript: |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
101 <example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
102 # npm install -g typescript |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
103 </example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
104 Компиляция TypeScript: |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
105 <example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
106 $ tsc test.ts |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
107 $ cat test.js |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
108 </example> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
109 Созданный файл <literal>test.js</literal> может использоваться напрямую в njs. |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
110 </para> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
111 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
112 </section> |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
113 |
0e6bbd8138c4
Added article about TypeScript in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff
changeset
|
114 </article> |