Skip to content

Commit 49e0bae

Browse files
committed
up
1 parent ce78039 commit 49e0bae

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

typescript.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,28 @@ fn.bar // 不报错
14621462
* 接口泛型,在没有使用具体的属性时,互相兼容
14631463
* 函数泛型,定义的函数可以互相兼容,因为没有在调用额时候传入具体的类型
14641464

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+
14651487
# 注意
14661488

14671489
* 所有的类型都是在定义的时候规定的,在赋值的右边是不需要去定义类型的

0 commit comments

Comments
 (0)