Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 32fb806

Browse filesBrowse files
ts-axios
1 parent 0369e46 commit 32fb806
Copy full SHA for 32fb806

49 files changed

+16,678-22Lines changed: 16678 additions & 22 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎18-TypeScript/01-入门.html‎

Copy file name to clipboardExpand all lines: 18-TypeScript/01-入门.html
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<!--
99
$ npm install -g typescript
10+
$ yarn global add typescript
1011
$ tsc helloworld.ts
1112
1213
安装typescript插件
Collapse file

‎18-TypeScript/02-1-变量申明.ts‎

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// var
2+
// let
3+
// const
4+
// 解构
5+
// 展开
Collapse file

‎18-TypeScript/02-dataType.ts‎

Copy file name to clipboardExpand all lines: 18-TypeScript/02-dataType.ts
+58-22Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,73 @@
33
* Array Enum
44
* Any Void
55
*/
6-
// Boolean Number String
7-
var bool:boolean = false;
8-
var num:number = 10;
9-
var str:string = "sunshine";
10-
11-
// Array Enum
6+
// Boolean
7+
let isDone: boolean = false
8+
// Number
9+
let decLiteral: number = 20
10+
let hexLiteral: number = 0x14
11+
let binaryLiteral: number = 0b10100
12+
let octalLiteral: number = 0o24
13+
// String
14+
var nameStr: string = 'csxiaoyao'
15+
let sentence: string = `Hello, my name is ${ name }. I'm ${ decLiteral + 1 } years old.`
16+
// Array 两种方式
1217
var list1:number[] = [1,2,3];
1318
var list2:Array<string> = ["csxiaoyao","sunshine"];
1419

15-
enum Color {Red,Green=5,Blue=2,Purple};
16-
var colorName1:string = Color[1]; // undefined
17-
var colorName2:string = Color[5]; // Green
18-
var colorName3:string = Color[2]; // Blue
19-
var colorName4:string = Color[3]; // Purple
20-
var colorName5:string = Color[0]; // Red
21-
var c1:Color = Color.Green; // 5
22-
var c2:Color = Color.Red // 0
23-
var c3:Color = Color.Purple // 3
24-
25-
// Any Void
26-
var notSure:any = 10;
20+
// 【 Tuple 】 元祖,允许表示一个已知元素数量和类型的数组,各元素的类型不必相同
21+
let x: [string, number]
22+
x = ['hello', 10] // OK
23+
24+
// Enum
25+
enum Color { Red, Green=5, Blue=2, Purple };
26+
var colorName0: string = Color[0]; // Red
27+
var colorName1: string = Color[1]; // undefined
28+
var colorName2: string = Color[2]; // Blue
29+
var colorName3: string = Color[3]; // Purple
30+
var colorName5: string = Color[5]; // Green
31+
32+
var c1: Color = Color.Green; // 5
33+
var c2: Color = Color.Red // 0
34+
var c3: Color = Color.Purple // 3
35+
36+
// Any
37+
var notSure: any = 10;
2738
notSure = "Hello";
2839
notSure = false;
29-
var list:any[] = [10,"hello",false];
40+
var list: any[] = [10, "hello", false];
3041

31-
function say():void {
42+
// Void
43+
function say(): void {
3244
// body...
3345
}
34-
function tell():string {
46+
function tell(): string {
3547
alert(list1[0]);
3648
alert(list2[1]);
3749
return "sunshine";
3850
}
39-
tell();
51+
tell();
52+
53+
// null / undefined
54+
let u: undefined = undefined
55+
let n: null = null
56+
57+
// never,返回never的函数必须存在无法达到的终点
58+
function error(message: string): never {
59+
throw new Error(message)
60+
}
61+
function infiniteLoop(): never {
62+
while (true) {
63+
}
64+
}
65+
66+
// object
67+
// object 表示非原始类型,即除 number,string,boolean,symbol,null或undefined 之外的类型
68+
declare function create(o: object | null): void
69+
create({ prop: 0 }) // OK
70+
create(null) // OK
71+
72+
// 类型断言,两种方式
73+
let someValue: any = 'this is a string'
74+
let strLength1: number = (<string>someValue).length
75+
let strLength2: number = (someValue as string).length
Collapse file
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
.DS_Store
3+
node_modules/
Collapse file
+25Lines changed: 25 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# ts-axios-doc
2+
3+
TypeScript 从零实现 axios 文档教材
4+
5+
## 启动电子书
6+
7+
首先 clone 本项目:
8+
9+
```bash
10+
git clone https://git.imooc.com/coding-330/ts-axios-doc.git
11+
```
12+
13+
进入 `ts-axios-doc` 目录后安装项目依赖:
14+
15+
```bash
16+
npm install
17+
```
18+
19+
安装依赖后运行电子书:
20+
21+
```bash
22+
npm run dev
23+
```
24+
25+
浏览器打开 `http://localhost:8080/ts-axios/` 即可。
Collapse file
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
module.exports = {
2+
base: '/ts-axios/',
3+
dest: 'dist',
4+
title: 'TypeScript 从零实现 axios',
5+
description: '学习使用 TypeScript 从零实现 axios 库',
6+
themeConfig: {
7+
editLinks: false,
8+
docsDir: 'docs',
9+
nav: [],
10+
sidebar: [
11+
{
12+
title: '初识 TypeScript',
13+
collapsable: false,
14+
children: [
15+
['chapter1/', 'Introduction'],
16+
'chapter1/install',
17+
'chapter1/start'
18+
]
19+
},
20+
{
21+
title: 'TypeScript 常用语法',
22+
collapsable: false,
23+
children: [
24+
'chapter2/type',
25+
'chapter2/declare',
26+
'chapter2/interface',
27+
'chapter2/class',
28+
'chapter2/function',
29+
'chapter2/generic',
30+
'chapter2/inference',
31+
'chapter2/advance'
32+
]
33+
},
34+
{
35+
'title': 'ts-axios 项目初始化',
36+
collapsable: false,
37+
children: [
38+
'chapter3/require',
39+
'chapter3/init',
40+
'chapter3/base'
41+
]
42+
},
43+
{
44+
'title': 'ts-axios 基础功能实现',
45+
collapsable: false,
46+
children: [
47+
'chapter4/url',
48+
'chapter4/data',
49+
'chapter4/header',
50+
'chapter4/response',
51+
'chapter4/response-header',
52+
'chapter4/response-data'
53+
]
54+
},
55+
{
56+
'title': 'ts-axios 异常情况处理',
57+
collapsable: false,
58+
children: [
59+
'chapter5/error',
60+
'chapter5/enhance'
61+
]
62+
}
63+
]
64+
}
65+
}
Collapse file
77.1 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file
3.37 KB
  • Display the source diff
  • Display the rich diff
Loading
Collapse file
+6Lines changed: 6 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
home: true
3+
heroImage: /ts-logo.png
4+
actionText: 开始学习 →
5+
actionLink: /chapter1/
6+
---
Collapse file
+29Lines changed: 29 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# 初识 TypeScript
2+
3+
TypeScript 作为 JavaScript 语言的超级,它为 JavaScript 添加了可选择的类型标注,大大增强了代码的可读性和可维护性。同时,它提供最新和不断发展的 JavaScript 特性,能让我们建立更健壮的组件。
4+
5+
## TypeScript 的特点
6+
7+
TypeScript 主要有 3 大特点:
8+
9+
- **始于JavaScript,归于JavaScript**
10+
11+
TypeScript 可以编译出纯净、 简洁的 JavaScript 代码,并且可以运行在任何浏览器上、Node.js 环境中和任何支持 ECMAScript 3(或更高版本)的JavaScript 引擎中。
12+
13+
- **强大的工具构建大型应用程序**
14+
15+
类型允许 JavaScript 开发者在开发 JavaScript 应用程序时使用高效的开发工具和常用操作比如静态检查和代码重构。
16+
17+
类型是可选的,类型推断让一些类型的注释使你的代码的静态验证有很大的不同。类型让你定义软件组件之间的接口和洞察现有 JavaScript 库的行为。
18+
19+
- **先进的 JavaScript**
20+
21+
TypeScript 提供最新的和不断发展的 JavaScript 特性,包括那些来自 2015 年的 ECMAScript 和未来的提案中的特性,比如异步功能和 Decorators,以帮助建立健壮的组件。
22+
23+
这些特性为高可信应用程序开发时是可用的,但是会被编译成简洁的 ECMAScript3(或更新版本)的JavaScript。
24+
25+
## 总结
26+
27+
TypeScript 在社区的流行度越来越高,它非常适用于一些大型项目,也非常适用于一些基础库,极大地帮助我们提升了开发效率和体验。都 2019 年了,如果你还没有开始学习 TypeScript,那么你可能要落后了哟,所以还等什么,快来和我一起学习并使用 TypeScript 吧,来感受一下它为我们带来的奇妙体验。
28+
29+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.