摘要: 当我们想穷举一个类型的所有可能值时,当可能值过多,不免会遗漏过多的东西。 通常我们穷举一个值的所有可能,我们会采用switch或者if else,当然,这是可行的,下面看一个if else例子 function test(p:1|2){ if(p 1){ return 1 }else if(p 2) 阅读全文
posted @ 2020-12-17 23:24 Sebastian·S·Pan 阅读(406) 评论(0) 推荐(0) 编辑
摘要: ? 可选,等价于其之后的类型联合undefined的联合类型 type obj={ a:string, b?:string } //等价于 type obj={ a:string, b:string|undefined } 所以有如下的情况产生 let a:obj={a:"22"} a.b=null 阅读全文
posted @ 2020-12-17 22:27 Sebastian·S·Pan 阅读(65) 评论(0) 推荐(0) 编辑