We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ce78039 commit 49e0baeCopy full SHA for 49e0bae
typescript.md
@@ -1462,6 +1462,28 @@ fn.bar // 不报错
1462
* 接口泛型,在没有使用具体的属性时,互相兼容
1463
* 函数泛型,定义的函数可以互相兼容,因为没有在调用额时候传入具体的类型
1464
1465
+# ts 类型保护
1466
+
1467
+* ts 能够在特定的区块保证变量属于某种特定的类型
1468
1469
+ 可以在此区块中放心的使用该类型的属性和方法
1470
1471
+## 1. instanceof
1472
1473
+* 判断实例是否属于某个类
1474
1475
+## 2. in 关键字
1476
1477
+* 判断某个属性是否在这个对象中
1478
1479
+ ```typescript
1480
+ if ('java' in lang) {
1481
+ lang.java
1482
+ }
1483
+ ```
1484
1485
1486
1487
# 注意
1488
1489
* 所有的类型都是在定义的时候规定的,在赋值的右边是不需要去定义类型的
0 commit comments