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

 

posted on 2023-08-11 10:03  空白格k  阅读(21)  评论(0编辑  收藏  举报

导航