File tree Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Expand file tree Collapse file tree 1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -24,17 +24,20 @@ myFavoriteNumber = 7;
24
24
25
25
TypeScript 会在没有明确的指定类型的时候推测出一个类型,这就是类型推论。
26
26
27
- ** 如果定义的时候没有赋值,不管之后有没有赋值,都会被推断成 ` any ` 类型 ** :
27
+ ** 在TypeScript 2.1 之前, 如果定义的时候没有赋值,不管之后有没有赋值,都会被推断成 ` any ` 类型而完全不被类型检查 ** :
28
28
29
29
``` ts
30
30
let myFavoriteNumber;
31
31
myFavoriteNumber = ' seven' ;
32
32
myFavoriteNumber = 7 ;
33
33
```
34
34
35
+ ** TypeScript 2.1 中,编译器会考虑对 myFavoriteNumber 的最后一次赋值来检查类型** :[ 例] ( https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#improved-any-inference )
36
+
35
37
## 参考
36
38
37
39
- [ Type Inference] ( http://www.typescriptlang.org/docs/handbook/type-inference.html ) ([ 中文版] ( https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Type%20Inference.html ) )
40
+ - [ TypeScript 2.1 Release Note] ( https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html )
38
41
39
42
---
40
43
You can’t perform that action at this time.
0 commit comments