typeScript学习-TS类型-合成类型
typeScript学习
合成类型:联合类型, 交叉类型
联合类型:
let str:srting | number = "abc" str=3
交叉类型:
type Obj1 = {username:string} type Obj2 = {age:number} let obj:Obj1={username:'zhangsan'} let obj2:Obj2={age:23} let obj3:Obj1 & Obj2 = {username:'wangwu',age:30} // 错误情况 // let str2:string & number = 3