Skip to content

Commit 866f80f

Browse files
committed
Complete structure
1 parent 97df13b commit 866f80f

24 files changed

+240
-69
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,40 @@ TypeScript 虽然有[官方手册][Handbook]及其[非官方中文版][中文手
4747
- 没有系统学习过 JavaScript
4848
- 已经能够很熟练的运用 TypeScript
4949

50+
## 目录
51+
52+
- [前言](README.md)
53+
- [简介](introduction/README.md)
54+
- [什么是 TypeScript](introduction/what-is-typescript.md)
55+
- [安装 TypeScript](introduction/get-typescript.md)
56+
- [Hello TypeScript](introduction/hello-typescript.md)
57+
- [基础](basics/README.md)
58+
- [原始数据类型](basics/primitive-data-types.md)
59+
- [任意值](basics/any.md)
60+
- [类型推论](basics/type-inference.md)
61+
- [联合类型](basics/union-types.md)
62+
- [对象的类型——接口](basics/type-of-object-interfaces.md)
63+
- [数组的类型](basics/type-of-array.md)
64+
- [函数的类型](basics/type-of-function.md)
65+
- [类型断言](basics/type-assertion.md)
66+
- [声明文件](basics/declaration-files.md)
67+
- [内置对象](basics/built-in-objects.md)
68+
- [进阶](advanced/README.md)
69+
- [类型别名](advanced/type-aliases.md)
70+
- [字符串字面量类型](advanced/string-literal-types.md)
71+
- [元组](advanced/tuple.md)
72+
- [枚举](advanced/enum.md)
73+
- [](advanced/class.md)
74+
- [类与接口](advanced/class-and-interfaces.md)
75+
- [泛型](advanced/generics.md)
76+
- [声明合并](advanced/declaration-merging.md)
77+
- [扩展阅读](advanced/further-reading.md)
78+
- [实践](practice/README.md)
79+
- [编译选项](practice/tsconfig.md)
80+
- [代码检查](practice/tslint.md)
81+
- [构建工具](practice/build.md)
82+
- [感谢](thanks/README.md)
83+
5084
## 版权许可
5185

5286
本书采用「保持署名—非商用」创意共享 4.0 许可证。

SUMMARY.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@
1313
- [对象的类型——接口](basics/type-of-object-interfaces.md)
1414
- [数组的类型](basics/type-of-array.md)
1515
- [函数的类型](basics/type-of-function.md)
16+
- [类型断言](basics/type-assertion.md)
1617
- [声明文件](basics/declaration-files.md)
1718
- [内置对象](basics/built-in-objects.md)
18-
- 进阶(未完成)
19-
- [类的用法](advanced/use-of-class.md)
20-
- [类的类型](advanced/type-of-class.md)
19+
- [进阶](advanced/README.md)
20+
- [类型别名](advanced/type-aliases.md)
21+
- [字符串字面量类型](advanced/string-literal-types.md)
2122
- [元组](advanced/tuple.md)
2223
- [枚举](advanced/enum.md)
23-
- 实践(未完成)
24-
- 学习资料(未完成)
24+
- [](advanced/class.md)
25+
- [类与接口](advanced/class-and-interfaces.md)
26+
- [泛型](advanced/generics.md)
27+
- [声明合并](advanced/declaration-merging.md)
28+
- [扩展阅读](advanced/further-reading.md)
29+
- [实践](practice/README.md)
30+
- [编译选项](practice/tsconfig.md)
31+
- [代码检查](practice/tslint.md)
32+
- [构建工具](practice/build.md)
33+
- [感谢](thanks/README.md)

advanced/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
## 进阶
22

3+
TBD
4+
5+
- [类型别名](type-aliases.md)
6+
- [字符串字面量类型](string-literal-types.md)
7+
- [元组](tuple.md)
8+
- [枚举](enum.md)
9+
- [](class.md)
10+
- [类与接口](class-and-interfaces.md)
11+
- [泛型](generics.md)
12+
- [声明合并](declaration-merging.md)
13+
- [扩展阅读](further-reading.md)
14+
315
---
16+
17+
- [上一章:内置对象](built-in-objects.md)
18+
- [下一章:类型别名](type-aliases.md)

advanced/class-and-interfaces.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# 类与接口
2+
3+
TBD
4+
5+
## 类实现接口
6+
7+
实现(implements)是面向对象中的一个重要概念。一般来讲,一个类只能继承自另一个类,有时候不同类之间可以有一些共有的特性,这时候就可以把特性提取成接口(interfaces),用 `implements` 关键字来实现。这个特性大大提高了面向对象的灵活性。
8+
9+
举例来说,门是一个类,防盗门是门的子类。如果防盗门有一个报警器的功能,我们可以简单的给防盗门添加一个报警方法。这时候如果有另一个类,车,也有报警器的功能,就可以考虑把报警器提取出来,作为一个接口,防盗门和车都去实现它:
10+
11+
```ts
12+
interface Alarm {
13+
alert()
14+
}
15+
16+
class Door {
17+
}
18+
19+
class SecurityDoor extends Door implements Alarm {
20+
alert() {
21+
console.log('SecurityDoor alert');
22+
}
23+
}
24+
25+
class Car implements Alarm {
26+
alert() {
27+
console.log('Car alert');
28+
}
29+
}
30+
```
31+
32+
## 接口继承接口
33+
34+
TBD
35+
36+
## 接口继承类
37+
38+
TBD
39+
40+
## 混合类型
41+
42+
TBD
43+
44+
---
45+
46+
- [上一章:类](class.md)
47+
- [下一章:泛型](generics.md)

advanced/use-of-class.md renamed to advanced/class.md

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 类的用法
1+
#
22

33
传统方法中,JavaScript 通过构造函数实现类的概念,通过原型链实现继承。而在 ES6 中,我们终于迎来了 `class`
44

@@ -336,38 +336,14 @@ var Cat = (function (_super) {
336336
var cat = new Cat('Tom');
337337
```
338338

339-
### 类实现接口
340-
341-
接口在 TypeScript 中是一个非常灵活的概念,实际上,我们在[对象的类型——接口](../basics/type-of-object-interfaces.html)一章中,已经接触了接口的一种用法了。这里是接口的第二种用法。想了解接口的所有用法,可以参考???。
342-
343-
实现(implements)是面向对象中的一个重要概念。一般来讲,一个类只能继承自另一个类,有时候不同类之间可以有一些共有的特性,这时候就可以把特性提取成接口(interfaces),用 `implements` 关键字来实现。这个特性大大提高了面向对象的灵活性。
344-
345-
举例来说,门是一个类,防盗门是门的子类。如果防盗门有一个报警器的功能,我们可以简单的给防盗门添加一个报警方法。这时候如果有另一个类,车,也有报警器的功能,就可以考虑把报警器提取出来,作为一个接口,防盗门和车都去实现它:
346-
347-
```ts
348-
interface Alarm {
349-
alert()
350-
}
351-
352-
class Door {
353-
}
354-
355-
class SecurityDoor extends Door implements Alarm {
356-
alert() {
357-
console.log('SecurityDoor alert');
358-
}
359-
}
360-
361-
class Car implements Alarm {
362-
alert() {
363-
console.log('Car alert');
364-
}
365-
}
366-
```
367-
368339
## 参考
369340

370341
- [Handbook - Classes](http://www.typescriptlang.org/docs/handbook/classes.html) | [中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Classes.html)
371342
- [ECMAScript 6 入门 - Class]
372343

373344
[ECMAScript 6 入门 - Class]: http://es6.ruanyifeng.com/#docs/class
345+
346+
---
347+
348+
- [上一章:枚举](enum.md)
349+
- [下一章:类与接口](class-and-interfaces.md)

advanced/declaration-merging.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# 声明合并
2+
3+
TBD
4+
5+
---
6+
7+
- [上一章:泛型](generics.md)
8+
- [下一章:扩展阅读](further-reading.md)

advanced/enum.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,6 @@ var directions = [0 /* Up */, 1 /* Down */, 2 /* Left */, 3 /* Right */];
224224
[C# Enum]: https://msdn.microsoft.com/zh-cn/library/sbbt4032.aspx
225225

226226
---
227+
228+
- [上一章:元组](tuple.md)
229+
- [下一章:类](class.md)

advanced/further-reading.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 扩展阅读
2+
3+
此处记录了[官方手册](http://www.typescriptlang.org/docs/handbook/basic-types.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/))中包含,但是本书未涉及的概念。
4+
5+
我认为它们是一些不重要或者不属于 TypeScript 的概念,所以这里只给出一个简单的释义,详细内容可以点击链接深入理解。
6+
7+
- [Never](http://www.typescriptlang.org/docs/handbook/basic-types.html#never)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Basic%20Types.html#never)):永远不存在值的类型,一般用于错误处理函数
8+
- [变量声明](http://www.typescriptlang.org/docs/handbook/variable-declarations.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Variable%20Declarations.html)):使用 `let``const` 替代 `var`,这是 [ES6 的知识](http://es6.ruanyifeng.com/#docs/let)
9+
- [泛型#在泛型约束中使用类型参数](http://www.typescriptlang.org/docs/handbook/generics.html#using-type-parameters-in-generic-constraints)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Generics.html#在泛型约束中使用类型参数)):多个类型参数间可以互相约束
10+
- [泛型#在泛型里使用类类型](http://www.typescriptlang.org/docs/handbook/generics.html#using-class-types-in-generics)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Generics.html#在泛型里使用类类型)):创建工厂函数时,需要引用构造函数的类类型
11+
- [类型推论#最佳通用类型](http://www.typescriptlang.org/docs/handbook/type-inference.html#best-common-type)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Type%20Inference.html#最佳通用类型)):数组的类型推论
12+
- [类型推论#上下文类型](http://www.typescriptlang.org/docs/handbook/type-inference.html#contextual-type)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Type%20Inference.html#上下文类型)):函数输入的类型推论
13+
- [类型兼容性](http://www.typescriptlang.org/docs/handbook/type-compatibility.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Type%20Compatibility.html)):允许不严格符合类型,只需要在一定规则下兼容即可
14+
- [高级类型#交叉类型](http://www.typescriptlang.org/docs/handbook/advanced-types.html#intersection-types)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Advanced%20Types.html#交叉类型(intersection-types))):使用 `&` 将多种类型的共有部分叠加成一种类型
15+
- [高级类型#类型保护与区分类型](http://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Advanced%20Types.html#类型保护与区分类型(type-guards-and-differentiating-types))):联合类型在一些情况下被识别为特定的类型
16+
- [高级类型#可辨识联合](http://www.typescriptlang.org/docs/handbook/advanced-types.html#discriminated-unions)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Advanced%20Types.html#可辨识联合(discriminated-unions))):使用 `|` 联合多个接口的时候,通过一个共有的属性形成可辨识联合
17+
- [高级类型#多态的 `this` 类型](http://www.typescriptlang.org/docs/handbook/advanced-types.html#polymorphic-this-types)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Advanced%20Types.html#多态的this类型)):父类的某个方法返回 `this`,当子类继承父类后,子类的实例调用此方法,返回的 `this` 能够被 TypeScript 正确的识别为子类的实例。
18+
- [Symbols](http://www.typescriptlang.org/docs/handbook/symbols.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Symbols.html)):新原生类型,这是 [ES6 的知识](http://es6.ruanyifeng.com/#docs/symbol)
19+
- [Iterators 和 Generators](http://www.typescriptlang.org/docs/handbook/iterators-and-generators.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Iterators%20and%20Generators.html)):迭代器,这是 [ES6 的知识](http://es6.ruanyifeng.com/#docs/iterator)
20+
- [命名空间](http://www.typescriptlang.org/docs/handbook/namespaces.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Namespaces.html)):避免全局污染,现在已被 [ES6 Module](http://es6.ruanyifeng.com/#docs/module) 替代
21+
- [Decorators](http://www.typescriptlang.org/docs/handbook/decorators.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Decorators.html)):修饰器,这是 [ES7 的一个提案](http://es6.ruanyifeng.com/#docs/decorator)
22+
- [混入](http://www.typescriptlang.org/docs/handbook/mixins.html)[中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Mixins.html)):一种编程模式,与 TypeScript 没有直接关系,可以参考 [ES6 中 Mixin 模式的实现](http://es6.ruanyifeng.com/#docs/class#Mixin模式的实现)
23+
24+
---
25+
26+
- [上一章:声明合并](declaration-merging.md)
27+
- [下一章:实践](../practice/README.md)

advanced/generics.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,6 @@ TBD
134134
- [Handbook - Generics](http://www.typescriptlang.org/docs/handbook/generics.html) | [中文版](https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/generics.html)
135135

136136
---
137+
138+
- [上一章:类与接口](class-and-interfaces.md)
139+
- [下一章:声明合并](declaration-merging.md)

advanced/never.md

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)