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

Skip to content

Commit ca0ebbc

Browse files
committed
整理 introduction
1 parent 14c12f5 commit ca0ebbc

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
export DENO_INSTALL="/home/runner/.deno"
1818
export PATH="$DENO_INSTALL/bin:$PATH"
1919
deno --version
20-
deno install --unstable --allow-read --allow-write --allow-net -n pagic https://deno.land/x/[email protected].26/mod.ts
20+
deno install --unstable --allow-read --allow-write --allow-net -n pagic https://deno.land/x/[email protected].28/mod.ts
2121
pagic build
2222
2323
- name: Deploy

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ TypeScript 虽然有[官方手册][Handbook]及其[非官方中文版][中文手
3636

3737
[TypeScript] 是 JavaScript 的一个超集,主要提供了**类型系统****对 ES6 的支持**,它由 Microsoft 开发,代码[开源于 GitHub](https://github.com/Microsoft/TypeScript) 上。
3838

39-
它的第一个版本发布于 2012 年 10 月,经历了多次更新后,现在已成为前端社区中不可忽视的力量,不仅在 Microsoft 内部得到广泛运用,而且 Google [Angular2](https://angular.io/) 也使用了 TypeScript 作为开发语言。
39+
它的第一个版本发布于 2012 年 10 月,经历了多次更新后,现在已成为前端社区中不可忽视的力量,不仅在 Microsoft 内部得到广泛运用,而且 Google 开发的 [Angular](https://angular.io/) 从 2.0 开始就使用了 TypeScript 作为开发语言[Vue](https://vuejs.org/) 3.0 也使用 TypeScript 进行了重构
4040

4141
## 适合人群
4242

@@ -54,7 +54,7 @@ TypeScript 虽然有[官方手册][Handbook]及其[非官方中文版][中文手
5454

5555
## 评价
5656

57-
> 《TypeScript 入门教程》全面介绍了 TS 强大的类型系统,完整而简洁,示例丰富,比官方文档更易读,非常适合作为初学者学习 TS 的第一本书。
57+
> 《TypeScript 入门教程》全面介绍了 TypeScript 强大的类型系统,完整而简洁,示例丰富,比官方文档更易读,非常适合作为初学者学习 TypeScript 的第一本书。
5858
>
5959
> —— [阮一峰](https://github.com/ruanyf)
6060

introduction/get-typescript.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ tsc hello.ts
1818

1919
## 编辑器
2020

21-
TypeScript 最大的优势便是增强了编辑器和 IDE 的功能,包括代码补全、接口提示、跳转到定义、重构等。
21+
TypeScript 最大的优势之一便是增强了编辑器和 IDE 的功能,包括代码补全、接口提示、跳转到定义、重构等。
2222

2323
主流的编辑器都支持 TypeScript,这里我推荐使用 [Visual Studio Code](https://code.visualstudio.com/)
2424

25-
它是一款开源,跨终端的轻量级编辑器,内置了 TypeScript 支持
25+
它是一款开源,跨终端的轻量级编辑器,内置了对 TypeScript 的支持
2626

2727
另外它本身也是[用 TypeScript 编写的](https://github.com/Microsoft/vscode/)
2828

@@ -31,10 +31,10 @@ TypeScript 最大的优势便是增强了编辑器和 IDE 的功能,包括代
3131
获取其他编辑器或 IDE 对 TypeScript 的支持:
3232

3333
- [Sublime Text](https://github.com/Microsoft/TypeScript-Sublime-Plugin)
34-
- [Atom](https://atom.io/packages/atom-typescript)
3534
- [WebStorm](https://www.jetbrains.com/webstorm/)
3635
- [Vim](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Editor-Support#vim)
3736
- [Emacs](https://github.com/ananthakumaran/tide)
3837
- [Eclipse](https://github.com/palantir/eclipse-typescript)
39-
- [Visual Studio 2015](https://www.microsoft.com/en-us/download/details.aspx?id=48593)
40-
- [Visual Studio 2013](https://www.microsoft.com/en-us/download/details.aspx?id=48739)
38+
- [Atom](https://atom.io/packages/atom-typescript)
39+
- [Visual Studio 2019](https://marketplace.visualstudio.com/search?term=TypeScriptTeam&target=VS&category=All%20categories&vsVersion=vs2019&sortBy=UpdatedDate)
40+
- [Visual Studio 2017](https://marketplace.visualstudio.com/search?term=TypeScriptTeam&target=VS&category=All%20categories&vsVersion=vs15&sortBy=UpdatedDate)

introduction/hello-typescript.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,26 @@ var user = 'Tom';
2929
console.log(sayHello(user));
3030
```
3131

32-
TypeScript 中,使用 `:` 指定变量的类型,`:` 的前后有没有空格都可以。
32+
TypeScript 中,我们使用 `:` 指定变量的类型,`:` 的前后有没有空格都可以。
3333

3434
上述例子中,我们用 `:` 指定 `person` 参数类型为 `string`。但是编译为 js 之后,并没有什么检查的代码被插入进来。
3535

36-
**TypeScript 只会进行静态检查,如果发现有错误,编译的时候就会报错。**
36+
这是因为 **TypeScript 只会在编译时对类型进行静态检查,如果发现有错误,编译的时候就会报错。**而在运行时,与普通的 JavaScript 文件一样,不会对类型进行检查。
37+
38+
如果我们需要保证运行时的参数类型,还是得手动对类型进行判断:
39+
40+
```ts
41+
function sayHello(person: string) {
42+
if (typeof person === 'string') {
43+
return 'Hello, ' + person;
44+
} else {
45+
throw new Error('person is not a string');
46+
}
47+
}
48+
49+
let user = 'Tom';
50+
console.log(sayHello(user));
51+
```
3752

3853
> `let` 是 ES6 中的关键字,和 `var` 类似,用于定义一个局部变量,可以参阅 [let 和 const 命令](http://es6.ruanyifeng.com/#docs/let)
3954
@@ -51,7 +66,7 @@ console.log(sayHello(user));
5166
编辑器中会提示错误,编译的时候也会出错:
5267

5368
```bash
54-
index.ts(6,22): error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string'.
69+
hello.ts:6:22 - error TS2345: Argument of type 'number[]' is not assignable to parameter of type 'string'.
5570
```
5671

5772
但是还是生成了 js 文件:
@@ -64,6 +79,6 @@ var user = [0, 1, 2];
6479
console.log(sayHello(user));
6580
```
6681

67-
**TypeScript 编译的时候即使报错了,还是会生成编译结果**,我们仍然可以使用这个编译之后的文件。
82+
这是因为 **TypeScript 编译的时候即使报错了,还是会生成编译结果**,我们仍然可以使用这个编译之后的文件。
6883

6984
如果要在报错的时候终止 js 文件的生成,可以在 `tsconfig.json` 中配置 `noEmitOnError` 即可。关于 `tsconfig.json`,请参阅[官方手册](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/tsconfig.json.html))。

introduction/what-is-typescript.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@
2020

2121
- 类型系统实际上是最好的文档,大部分的函数看看类型的定义就可以知道如何使用了
2222
- 可以在编译阶段就发现大部分错误,这总比在运行时候出错好
23-
- 增强了编辑器和 IDE 的功能,包括代码补全、接口提示、跳转到定义、重构等
23+
- 增强了编辑器和 IDE 的功能,包括代码补全、接口提示、跳转到定义、代码重构等
2424

2525
### TypeScript 非常包容
2626

2727
- TypeScript 是 JavaScript 的超集,`.js` 文件可以直接重命名为 `.ts` 即可
2828
- 即使不显式的定义类型,也能够自动做出[类型推论](../basics/type-inference.md)
29-
- 可以定义从简单到复杂的几乎一切类型
29+
- TypeScript 的类型系统是图灵完备的,可以定义从简单到复杂的几乎一切类型
3030
- 即使 TypeScript 编译报错,也可以生成 JavaScript 文件
3131
- 兼容第三方库,即使第三方库不是用 TypeScript 写的,也可以编写单独的类型文件供 TypeScript 读取
3232

3333
### TypeScript 拥有活跃的社区
3434

3535
- 大部分第三方库都有提供给 TypeScript 的类型定义文件
36-
- Google 开发的 Angular2 就是使用 TypeScript 编写的
37-
- TypeScript 拥抱了 ES6 规范,也支持部分 ESNext 草案的规范
36+
- Angular、Vue、VS Code、Ant Design 等等耳熟能详的项目都是使用 TypeScript 编写的
37+
- TypeScript 拥抱了 ES6 规范,支持 ESNext 草案中处于第三阶状态(Stage 3)的特性
3838

3939
### TypeScript 的缺点
4040

pagic.config.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ export default {
6767
},
6868
'thanks/README.md'
6969
],
70+
tools: {
71+
editOnGithub: true,
72+
backToTop: true
73+
},
7074
tocAd: (
7175
<div
7276
dangerouslySetInnerHTML={{

0 commit comments

Comments
 (0)