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;
2424
2525TypeScript 会在没有明确的指定类型的时候推测出一个类型,这就是类型推论。
2626
27- ** 如果定义的时候没有赋值,不管之后有没有赋值,都会被推断成 ` any ` 类型 ** :
27+ ** 在TypeScript 2.1 之前, 如果定义的时候没有赋值,不管之后有没有赋值,都会被推断成 ` any ` 类型而完全不被类型检查 ** :
2828
2929``` ts
3030let myFavoriteNumber;
3131myFavoriteNumber = ' seven' ;
3232myFavoriteNumber = 7 ;
3333```
3434
35+ ** TypeScript 2.1 中,编译器会考虑对 myFavoriteNumber 的最后一次赋值来检查类型** :[ 例] ( https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#improved-any-inference )
36+
3537## 参考
3638
3739- [ 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 )
3841
3942---
4043
You can’t perform that action at this time.
0 commit comments