Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3b73ba

Browse files
doggy8088gitbook-bot
authored andcommitted
GitBook: [master] 2 pages modified
1 parent ca1c97b commit d3b73ba

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

advanced/string-literal-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 字串字面量型別
22

3-
字串字面量型別用來約束取值只能是某幾個字串中的一個
3+
字串字面量 \(String Literal\) 型別用來約束取值只能是某幾個字串中的一個
44

55
## 簡單的例子
66

basics/declaration-files.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66

77
由於本章涉及大量新語法,故在本章開頭列出新語法的索引,方便大家在使用這些新語法時能快速查詢到對應的講解:
88

9-
* [`declare var`](declaration-files.md#declare-var) 宣告全域變數
10-
* [`declare function`](declaration-files.md#declare-function) 宣告全域方法
11-
* [`declare class`](declaration-files.md#declare-class) 宣告全域類別
12-
* [`declare enum`](declaration-files.md#declare-enum) 宣告全域列舉型別
13-
* [`declare namespace`](declaration-files.md#declare-namespace) 宣告(含有子屬性的)全域物件
14-
* [`interface``type`](declaration-files.md#interface-he-type) 宣告全域型別
9+
* [`declare var`](declaration-files.md#declare-var) 宣告全域性變數
10+
* [`declare function`](declaration-files.md#declare-function) 宣告全域性方法
11+
* [`declare class`](declaration-files.md#declare-class) 宣告全域性類別
12+
* [`declare enum`](declaration-files.md#declare-enum) 宣告全域性列舉型別
13+
* [`declare namespace`](declaration-files.md#declare-namespace) 宣告(含有子屬性的)全域性物件
14+
* [`interface``type`](declaration-files.md#interface-he-type) 宣告全域性型別
1515
* [`export`](declaration-files.md#export) 匯出變數
1616
* [`export namespace`](declaration-files.md#export-namespace) 匯出(含有子屬性的)物件
1717
* [`export default`](declaration-files.md#export-default) ES6 預設匯出
1818
* [`export =`](declaration-files.md#export-1) commonjs 匯出模組
19-
* [`export as namespace`](declaration-files.md#export-as-namespace) UMD 函式庫宣告全域變數
20-
* [`declare global`](declaration-files.md#declare-global) 擴充套件全域變數
19+
* [`export as namespace`](declaration-files.md#export-as-namespace) UMD 函式庫宣告全域性變數
20+
* [`declare global`](declaration-files.md#declare-global) 擴充套件全域性變數
2121
* [`declare module`](declaration-files.md#declare-module) 擴充套件模組
2222
* [`/// <reference />`](declaration-files.md#san-xie-xian-zhi-ling) 三斜線指令
2323

2424
## 什麼是宣告語句
2525

26-
假如我們想使用第三方函式庫 jQuery,一種常見的方式是在 html 中透過 `<script>` 標籤引入 jQuery,然後就可以使用全域變數 `$``jQuery` 了。
26+
假如我們想使用第三方函式庫 jQuery,一種常見的方式是在 html 中透過 `<script>` 標籤引入 jQuery,然後就可以使用全域性變數 `$``jQuery` 了。
2727

2828
我們通常這樣獲取一個 `id``foo` 的元素:
2929

@@ -48,7 +48,7 @@ declare var jQuery: (selector: string) => any;
4848
jQuery('#foo');
4949
```
5050

51-
上例中,`declare var` 並沒有真的定義一個變數,只是定義了全域變數 `jQuery` 的型別,僅僅會用於編譯時的檢查,在編譯結果中會被刪除。它編譯結果是:
51+
上例中,`declare var` 並沒有真的定義一個變數,只是定義了全域性變數 `jQuery` 的型別,僅僅會用於編譯時的檢查,在編譯結果中會被刪除。它編譯結果是:
5252

5353
```javascript
5454
jQuery('#foo');
@@ -86,7 +86,7 @@ jQuery('#foo');
8686

8787
假如仍然無法解析,那麼可以檢查下 `tsconfig.json` 中的 `files``include``exclude` 配置,確保其包含了 `jQuery.d.ts` 檔案。
8888

89-
這裡只演示了全域變數這種模式的宣告檔案,假如是透過模組匯入的方式使用第三方函式庫的話,那麼引入宣告檔案又是另一種方式了,將會在後面詳細介紹。
89+
這裡只演示了全域性變數這種模式的宣告檔案,假如是透過模組匯入的方式使用第三方函式庫的話,那麼引入宣告檔案又是另一種方式了,將會在後面詳細介紹。
9090

9191
### 第三方宣告檔案
9292

@@ -133,7 +133,7 @@ npm install @types/jquery --save-dev
133133

134134
如果沒有生效,可以檢查下 `tsconfig.json` 中的 `files``include``exclude` 配置,確保其包含了 `jQuery.d.ts` 檔案。
135135

136-
全域變數的宣告檔案主要有以下幾種語法
136+
全域性變數的宣告檔案主要有以下幾種語法
137137

138138
* [`declare var`](declaration-files.md#declare-var) 宣告全域變數
139139
* [`declare function`](declaration-files.md#declare-function) 宣告全域方法
@@ -190,7 +190,7 @@ declare const jQuery = function(selector) {
190190

191191
#### `declare function`
192192

193-
`declare function` 用來定義全域函式的型別。jQuery 其實就是一個函式,所以也可以用 `function` 來定義:
193+
`declare function` 用來定義全域性函式的型別。jQuery 其實就是一個函式,所以也可以用 `function` 來定義:
194194

195195
```typescript
196196
// src/jQuery.d.ts
@@ -392,7 +392,7 @@ jQuery.fn.extend({
392392

393393
#### `interface``type`
394394

395-
除了全域變數之外,可能有一些型別我們也希望能暴露出來。在型別宣告檔案中,我們可以直接使用 `interface``type` 來宣告一個全域的介面或型別[12](https://github.com/xcatliu/typescript-tutorial/tree/master/examples/declaration-files/12-interface)
395+
除了全域變數之外,可能有一些型別我們也希望能暴露出來。在型別宣告檔案中,我們可以直接使用 `interface``type` 來宣告一個全域性的介面或型別[12](https://github.com/xcatliu/typescript-tutorial/tree/master/examples/declaration-files/12-interface)
396396

397397
```typescript
398398
// src/jQuery.d.ts
@@ -424,7 +424,7 @@ jQuery.ajax('/api/post_something', settings);
424424

425425
**防止命名衝突**
426426

427-
暴露在最外層的 `interface``type` 會作為全域型別作用於整個專案中,我們應該儘可能的減少全域變數或全域型別的數量。故最好將他們放到 `namespace`[13](https://github.com/xcatliu/typescript-tutorial/tree/master/examples/declaration-files/13-avoid-name-conflict)
427+
暴露在最外層的 `interface``type` 會作為全域性型別作用於整個專案中,我們應該儘可能的減少全域變數或全域性型別的數量。故最好將他們放到 `namespace`[13](https://github.com/xcatliu/typescript-tutorial/tree/master/examples/declaration-files/13-avoid-name-conflict)
428428

429429
```typescript
430430
// src/jQuery.d.ts

0 commit comments

Comments
 (0)