Skip to content

Commit 1f9ab31

Browse files
committed
satisfy lint
1 parent 1f3f701 commit 1f9ab31

File tree

130 files changed

+7330
-6966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+7330
-6966
lines changed

PREFACE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 前言
22

3-
> Repo: https://github.com/zhongsp/TypeScript
3+
> Repo: [https://github.com/zhongsp/TypeScript](https://github.com/zhongsp/TypeScript)
44
55
该工程是对 TypeScript 官方及开源社区书写的编程手册、版本发布说明等综合内容的中文翻译。
66
感谢 Microsoft 和开源社区的工程师们的工作,为 JavaScript 开发带来了全新的体验!

lint.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var options = {
99
MD001: false, // Header levels should only increment by one level at a time
1010
MD002: false, // First header should be a h1 header
1111
MD003: "atx", // Header style
12-
MD004: { style: "asterisk" }, // Unordered list style
12+
MD004: { style: "consistent" }, // Unordered list style
1313
MD005: true, // Inconsistent indentation for list items at the same level
1414
MD006: true, // Consider starting bulleted lists at the beginning of the line
1515
MD007: { indent: 2 }, // Unordered list indentation
@@ -30,7 +30,7 @@ var options = {
3030
MD026: { punctuation: ".,;:!" }, // Trailing punctuation in header
3131
MD027: true, // Multiple spaces after blockquote symbol
3232
MD028: true, // Blank line inside blockquote
33-
MD029: { style: "ordered" }, // Ordered list item prefix
33+
MD029: { style: "one_or_ordered" }, // Ordered list item prefix
3434
MD030: true, // Spaces after list markers
3535
MD031: true, // Fenced code blocks should be surrounded by blank lines
3636
MD032: true, // Lists should be surrounded by blank lines

zh/breaking-changes/README.md

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
# Breaking Changes
22

3-
* [TypeScript 3.6](typescript-3.6.md)
4-
* [TypeScript 3.5](typescript-3.5.md)
5-
* [TypeScript 3.4](typescript-3.4.md)
6-
* [TypeScript 3.2](typescript-3.2.md)
7-
* [TypeScript 3.1](typescript-3.1.md)
8-
* [TypeScript 3.0](typescript-3.0.md)
9-
* [TypeScript 2.9](typescript-2.9.md)
10-
* [TypeScript 2.8](typescript-2.8.md)
11-
* [TypeScript 2.7](typescript-2.7.md)
12-
* [TypeScript 2.6](typescript-2.6.md)
13-
* [TypeScript 2.4](typescript-2.4.md)
14-
* [TypeScript 2.3](typescript-2.3.md)
15-
* [TypeScript 2.2](typescript-2.2.md)
16-
* [TypeScript 2.1](typescript-2.1.md)
17-
* [TypeScript 2.0](typescript-2.0.md)
18-
* [TypeScript 1.8](typescript-1.8.md)
19-
* [TypeScript 1.7](typescript-1.7.md)
20-
* [TypeScript 1.6](typescript-1.6.md)
21-
* [TypeScript 1.5](typescript-1.5.md)
22-
* [TypeScript 1.4](typescript-1.4.md)
23-
* [TypeScript 1.1](typescript-1.1.md)
24-
3+
- [TypeScript 3.6](typescript-3.6.md)
4+
- [TypeScript 3.5](typescript-3.5.md)
5+
- [TypeScript 3.4](typescript-3.4.md)
6+
- [TypeScript 3.2](typescript-3.2.md)
7+
- [TypeScript 3.1](typescript-3.1.md)
8+
- [TypeScript 3.0](typescript-3.0.md)
9+
- [TypeScript 2.9](typescript-2.9.md)
10+
- [TypeScript 2.8](typescript-2.8.md)
11+
- [TypeScript 2.7](typescript-2.7.md)
12+
- [TypeScript 2.6](typescript-2.6.md)
13+
- [TypeScript 2.4](typescript-2.4.md)
14+
- [TypeScript 2.3](typescript-2.3.md)
15+
- [TypeScript 2.2](typescript-2.2.md)
16+
- [TypeScript 2.1](typescript-2.1.md)
17+
- [TypeScript 2.0](typescript-2.0.md)
18+
- [TypeScript 1.8](typescript-1.8.md)
19+
- [TypeScript 1.7](typescript-1.7.md)
20+
- [TypeScript 1.6](typescript-1.6.md)
21+
- [TypeScript 1.5](typescript-1.5.md)
22+
- [TypeScript 1.4](typescript-1.4.md)
23+
- [TypeScript 1.1](typescript-1.1.md)

zh/breaking-changes/typescript-1.4.md

+40-26
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,28 @@ var bs: { x: number; y?: number; z?: number }[] = [b, a];
2727

2828
## 泛型接口
2929

30-
当在多个T类型的参数上使用了不同的类型时会得到一个错误,就算是添加约束也不行:
30+
当在多个 T 类型的参数上使用了不同的类型时会得到一个错误,就算是添加约束也不行:
3131

3232
```typescript
33-
declare function foo<T>(x: T, y:T): T;
34-
var r = foo(1, ""); // r used to be {}, now this is an error
33+
declare function foo<T>(x: T, y: T): T;
34+
var r = foo(1, ''); // r used to be {}, now this is an error
3535
```
3636

3737
添加约束:
3838

3939
```typescript
40-
interface Animal { x }
41-
interface Giraffe extends Animal { y }
42-
interface Elephant extends Animal { z }
43-
function f<T extends Animal>(x: T, y: T): T { return undefined; }
40+
interface Animal {
41+
x;
42+
}
43+
interface Giraffe extends Animal {
44+
y;
45+
}
46+
interface Elephant extends Animal {
47+
z;
48+
}
49+
function f<T extends Animal>(x: T, y: T): T {
50+
return undefined;
51+
}
4452
var g: Giraffe;
4553
var e: Elephant;
4654
f(g, e);
@@ -51,66 +59,72 @@ f(g, e);
5159
**推荐** 如果这种不匹配的行为是故意为之,那么明确指定类型参数:
5260

5361
```typescript
54-
var r = foo<{}>(1, ""); // Emulates 1.0 behavior
55-
var r = foo<string|number>(1, ""); // Most useful
56-
var r = foo<any>(1, ""); // Easiest
62+
var r = foo<{}>(1, ''); // Emulates 1.0 behavior
63+
var r = foo<string | number>(1, ''); // Most useful
64+
var r = foo<any>(1, ''); // Easiest
5765
f<Animal>(g, e);
5866
```
5967

60-
_或_重写函数定义指明就算不匹配也没问题
68+
**重写函数定义指明就算不匹配也没问题
6169

6270
```typescript
63-
declare function foo<T,U>(x: T, y:U): T|U;
64-
function f<T extends Animal, U extends Animal>(x: T, y: U): T|U { return undefined; }
71+
declare function foo<T, U>(x: T, y: U): T | U;
72+
function f<T extends Animal, U extends Animal>(x: T, y: U): T | U {
73+
return undefined;
74+
}
6575
```
6676

6777
## 泛型剩余参数
6878

6979
不能再使用混杂的参数类型:
7080

7181
```typescript
72-
function makeArray<T>(...items: T[]): T[] { return items; }
73-
var r = makeArray(1, ""); // used to return {}[], now an error
82+
function makeArray<T>(...items: T[]): T[] {
83+
return items;
84+
}
85+
var r = makeArray(1, ''); // used to return {}[], now an error
7486
```
7587

7688
`new Array(...)`也一样
7789

78-
**推荐** 声明向后兼容的签名,如果1.0的行为是你想要的
90+
**推荐** 声明向后兼容的签名,如果 1.0 的行为是你想要的
7991

8092
```typescript
8193
function makeArray<T>(...items: T[]): T[];
8294
function makeArray(...items: {}[]): {}[];
83-
function makeArray<T>(...items: T[]): T[] { return items; }
95+
function makeArray<T>(...items: T[]): T[] {
96+
return items;
97+
}
8498
```
8599

86100
## 带类型参数接口的重载解析
87101

88102
```typescript
89103
var f10: <T>(x: T, b: () => (a: T) => void, y: T) => T;
90-
var r9 = f10('', () => (a => a.foo), 1); // r9 was any, now this is an error
104+
var r9 = f10('', () => a => a.foo, 1); // r9 was any, now this is an error
91105
```
92106

93107
**推荐** 手动指定一个类型参数
94108

95109
```typescript
96-
var r9 = f10<any>('', () => (a => a.foo), 1);
110+
var r9 = f10<any>('', () => a => a.foo, 1);
97111
```
98112

99113
## 类声明与类型表达式以严格模式解析
100114

101-
ECMAScript 2015语言规范\(ECMA-262 6th Edition\)指明_ClassDeclaration_和_ClassExpression_使用严格模式。 因此,在解析类声明或类表达式时将使用额外的限制。
115+
ECMAScript 2015 语言规范\(ECMA-262 6th Edition\)指明*ClassDeclaration**ClassExpression*使用严格模式。 因此,在解析类声明或类表达式时将使用额外的限制。
102116

103117
例如:
104118

105119
```typescript
106-
class implements {} // Invalid: implements is a reserved word in strict mode
120+
class implements {} // Invalid: implements is a reserved word in strict mode
107121
class C {
108-
foo(arguments: any) { // Invalid: "arguments" is not allow as a function argument
109-
var eval = 10; // Invalid: "eval" is not allowed as the left-hand-side expression
110-
arguments = []; // Invalid: arguments object is immutable
111-
}
122+
foo(arguments: any) {
123+
// Invalid: "arguments" is not allow as a function argument
124+
var eval = 10; // Invalid: "eval" is not allowed as the left-hand-side expression
125+
arguments = []; // Invalid: arguments object is immutable
126+
}
112127
}
113128
```
114129

115130
关于严格模式限制的完整列表,请阅读 Annex C - The Strict Mode of ECMAScript of ECMA-262 6th Edition。
116-

zh/breaking-changes/typescript-1.5.md

+60-55
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
## 不允许在箭头函数里引用`arguments`
66

7-
这是为了遵循ES6箭头函数的语义。之前箭头函数里的`arguments`会绑定到箭头函数的参数。参照[ES6规范草稿](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts) 9.2.12,箭头函数不存在`arguments`对象。 从TypeScript 1.5开始,在箭头函数里使用`arguments`会被标记成错误以确保你的代码转成ES6时没语义上的错误
7+
这是为了遵循 ES6 箭头函数的语义。之前箭头函数里的`arguments`会绑定到箭头函数的参数。参照[ES6 规范草稿](http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts) 9.2.12,箭头函数不存在`arguments`对象。 从 TypeScript 1.5 开始,在箭头函数里使用`arguments`会被标记成错误以确保你的代码转成 ES6 时没语义上的错误
88

99
**例子:**
1010

1111
```typescript
1212
function f() {
13-
return () => arguments; // Error: The 'arguments' object cannot be referenced in an arrow function.
13+
return () => arguments; // Error: The 'arguments' object cannot be referenced in an arrow function.
1414
}
1515
```
1616

@@ -19,101 +19,106 @@ function f() {
1919
```typescript
2020
// 1. 使用带名字的剩余参数
2121
function f() {
22-
return (...args) => { args; }
22+
return (...args) => {
23+
args;
24+
};
2325
}
2426

2527
// 2. 使用函数表达式
2628
function f() {
27-
return function(){ arguments; }
29+
return function () {
30+
arguments;
31+
};
2832
}
2933
```
3034

3135
## 内联枚举引用的改动
3236

33-
对于正常的枚举,在1.5之前,编译器_仅会_内联常量成员,且成员仅在使用字面量初始化时才被当做是常量。这在判断检举值是使用字面量初始化还是表达式时会行为不一致。从TypeScript 1.5开始,所有非const枚举成员都不会被内联
37+
对于正常的枚举,在 1.5 之前,编译器*仅会*内联常量成员,且成员仅在使用字面量初始化时才被当做是常量。这在判断检举值是使用字面量初始化还是表达式时会行为不一致。从 TypeScript 1.5 开始,所有非 const 枚举成员都不会被内联
3438

3539
**例子:**
3640

3741
```typescript
38-
var x = E.a; // previously inlined as "var x = 1; /*E.a*/"
42+
var x = E.a; // previously inlined as "var x = 1; /*E.a*/"
3943

4044
enum E {
41-
a = 1
45+
a = 1,
4246
}
4347
```
4448

4549
**推荐:** 在枚举声明里添加`const`修饰符来确保它总是被内联。 更多信息,查看[\#2183](https://github.com/Microsoft/TypeScript/issues/2183)
4650

4751
## 上下文的类型将作用于`super`和括号表达式
4852

49-
在1.5之前,上下文的类型不会作用于括号表达式内部。这就要求做显示的类型转换,尤其是在_必须_使用括号来进行表达式转换的场合
53+
在 1.5 之前,上下文的类型不会作用于括号表达式内部。这就要求做显示的类型转换,尤其是在*必须*使用括号来进行表达式转换的场合
5054

5155
在下面的例子里,`m`具有上下文的类型,它在之前的版本里是没有的。
5256

5357
```typescript
54-
var x: SomeType = (n) => ((m) => q);
55-
var y: SomeType = t ? (m => m.length) : undefined;
58+
var x: SomeType = n => m => q;
59+
var y: SomeType = t ? m => m.length : undefined;
5660

5761
class C extends CBase<string> {
58-
constructor() {
59-
super({
60-
method(m) { return m.length; }
61-
});
62-
}
62+
constructor() {
63+
super({
64+
method(m) {
65+
return m.length;
66+
},
67+
});
68+
}
6369
}
6470
```
6571

6672
更多信息,查看[\#1425](https://github.com/Microsoft/TypeScript/issues/1425)[\#920](https://github.com/Microsoft/TypeScript/issues/920)
6773

68-
## DOM接口的改动
74+
## DOM 接口的改动
6975

70-
TypeScript 1.5改进了`lib.d.ts`库里的DOM类型。这是自TypeScript 1.0以来第一次大的改动;为了拥抱标准DOM规范,很多特定于IE的定义被移除了,同时添加了新的类型如Web Audio和触摸事件
76+
TypeScript 1.5 改进了`lib.d.ts`库里的 DOM 类型。这是自 TypeScript 1.0 以来第一次大的改动;为了拥抱标准 DOM 规范,很多特定于 IE 的定义被移除了,同时添加了新的类型如 Web Audio 和触摸事件
7177

7278
**变通方案:**
7379

74-
你可以使用旧的`lib.d.ts`配合新版本的编译器。你需要在你的工程里引入之前版本的一个拷贝。这里是[本次改动之前的lib.d.ts文件\(TypeScript 1.5-alpha\)](https://github.com/Microsoft/TypeScript/blob/v1.5.0-alpha/bin/lib.d.ts)
80+
你可以使用旧的`lib.d.ts`配合新版本的编译器。你需要在你的工程里引入之前版本的一个拷贝。这里是[本次改动之前的 lib.d.ts 文件\(TypeScript 1.5-alpha\)](https://github.com/Microsoft/TypeScript/blob/v1.5.0-alpha/bin/lib.d.ts)
7581

7682
**变动列表:**
7783

78-
* 属性`selection``Document`类型上移除
79-
* 属性`clipboardData``Window`类型上移除
80-
* 删除接口`MSEventAttachmentTarget`
81-
* 属性`onresize``disabled``uniqueID``removeNode``fireEvent``currentStyle``runtimeStyle``HTMLElement`类型上移除
82-
* 属性`url``Event`类型上移除
83-
* 属性`execScript``navigate``item``Window`类型上移除
84-
* 属性`documentMode``parentWindow``createEventObject``Document`类型上移除
85-
* 属性`parentWindow``HTMLDocument`类型上移除
86-
* 属性`setCapture`被完全移除
87-
* 属性`releaseCapture`被完全移除
88-
* 属性`setAttribute``styleFloat``pixelLeft``CSSStyleDeclaration`类型上移除
89-
* 属性`selectorText``CSSRule`类型上移除
90-
* `CSSStyleSheet.rules`现在是`CSSRuleList`类型,而非`MSCSSRuleList`
91-
* `documentElement`现在是`Element`类型,而非`HTMLElement`
92-
* `Event`具有一个新的必需属性`returnValue`
93-
* `Node`具有一个新的必需属性`baseURI`
94-
* `Element`具有一个新的必需属性`classList`
95-
* `Location`具有一个新的必需属性`origin`
96-
* 属性`MSPOINTER_TYPE_MOUSE``MSPOINTER_TYPE_TOUCH``MSPointerEvent`类型上移除
97-
* `CSSStyleRule`具有一个新的必需属性`readonly`
98-
* 属性`execUnsafeLocalFunction``MSApp`类型上移除
99-
* 全局方法`toStaticHTML`被移除
100-
* `HTMLCanvasElement.getContext`现在返回`CanvasRenderingContext2D | WebGLRenderingContex`
101-
* 移除扩展类型`Dataview``Weakmap``Map``Set`
102-
* `XMLHttpRequest.send`具有两个重载`send(data?: Document): void;``send(data?: String): void;`
103-
* `window.orientation`现在是`string`类型,而非`number`
104-
* 特定于IE的`attachEvent``detachEvent``Window`上移除
105-
106-
**以下是被新加的DOM类型所部分或全部取代的代码库的代表**
107-
108-
* `DefinitelyTyped/auth0/auth0.d.ts`
109-
* `DefinitelyTyped/gamepad/gamepad.d.ts`
110-
* `DefinitelyTyped/interactjs/interact.d.ts`
111-
* `DefinitelyTyped/webaudioapi/waa.d.ts`
112-
* `DefinitelyTyped/webcrypto/WebCrypto.d.ts`
84+
- 属性`selection``Document`类型上移除
85+
- 属性`clipboardData``Window`类型上移除
86+
- 删除接口`MSEventAttachmentTarget`
87+
- 属性`onresize``disabled``uniqueID``removeNode``fireEvent``currentStyle``runtimeStyle``HTMLElement`类型上移除
88+
- 属性`url``Event`类型上移除
89+
- 属性`execScript``navigate``item``Window`类型上移除
90+
- 属性`documentMode``parentWindow``createEventObject``Document`类型上移除
91+
- 属性`parentWindow``HTMLDocument`类型上移除
92+
- 属性`setCapture`被完全移除
93+
- 属性`releaseCapture`被完全移除
94+
- 属性`setAttribute``styleFloat``pixelLeft``CSSStyleDeclaration`类型上移除
95+
- 属性`selectorText``CSSRule`类型上移除
96+
- `CSSStyleSheet.rules`现在是`CSSRuleList`类型,而非`MSCSSRuleList`
97+
- `documentElement`现在是`Element`类型,而非`HTMLElement`
98+
- `Event`具有一个新的必需属性`returnValue`
99+
- `Node`具有一个新的必需属性`baseURI`
100+
- `Element`具有一个新的必需属性`classList`
101+
- `Location`具有一个新的必需属性`origin`
102+
- 属性`MSPOINTER_TYPE_MOUSE``MSPOINTER_TYPE_TOUCH``MSPointerEvent`类型上移除
103+
- `CSSStyleRule`具有一个新的必需属性`readonly`
104+
- 属性`execUnsafeLocalFunction``MSApp`类型上移除
105+
- 全局方法`toStaticHTML`被移除
106+
- `HTMLCanvasElement.getContext`现在返回`CanvasRenderingContext2D | WebGLRenderingContex`
107+
- 移除扩展类型`Dataview``Weakmap``Map``Set`
108+
- `XMLHttpRequest.send`具有两个重载`send(data?: Document): void;``send(data?: String): void;`
109+
- `window.orientation`现在是`string`类型,而非`number`
110+
- 特定于 IE 的`attachEvent``detachEvent``Window`上移除
111+
112+
**以下是被新加的 DOM 类型所部分或全部取代的代码库的代表**
113+
114+
- `DefinitelyTyped/auth0/auth0.d.ts`
115+
- `DefinitelyTyped/gamepad/gamepad.d.ts`
116+
- `DefinitelyTyped/interactjs/interact.d.ts`
117+
- `DefinitelyTyped/webaudioapi/waa.d.ts`
118+
- `DefinitelyTyped/webcrypto/WebCrypto.d.ts`
113119

114120
更多信息,查看[完整改动](https://github.com/Microsoft/TypeScript/pull/2739)
115121

116122
## 类代码体将以严格格式解析
117123

118-
按照[ES6规范](http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code),类代码体现在以严格模式进行解析。行为将相当于在类作用域顶端定义了`"use strict"`;它包括限制了把`arguments``eval`做为变量名或参数名的使用,把未来保留字做为变量或参数使用,八进制数字字面量的使用等。
119-
124+
按照[ES6 规范](http://www.ecma-international.org/ecma-262/6.0/#sec-strict-mode-code),类代码体现在以严格模式进行解析。行为将相当于在类作用域顶端定义了`"use strict"`;它包括限制了把`arguments``eval`做为变量名或参数名的使用,把未来保留字做为变量或参数使用,八进制数字字面量的使用等。

0 commit comments

Comments
 (0)