美文网首页
Typescript 中 “?” 和 “!” "&" "|"

Typescript 中 “?” 和 “!” "&" "|"

作者: 如果俞天阳会飞 | 来源:发表于2022-05-25 14:02 被阅读0次

非空断言操作符 !

function Test(input: string | null):string {
  return input;
}
function Test(input: string | null):string {
  return input!;
}

可选属性 ?

interface Test {
  height?: number;
  width: number;
}

交集

type Env1 = '1' | '2' | '3';
type Env2 = '1' | '4' | '5';

type EnvUnion = Env1 | Env2; // '1' | '2' | '3' | '4' | '5'
type EnvInter = Env1 & Env2; // '1'

相关文章

网友评论

      本文标题:Typescript 中 “?” 和 “!” "&" "|"

      本文链接:https://www.haomeiwen.com/subject/nlveprtx.html