首页 > 其他分享 >[Typescript] Constraining Types for Anything but null or undefined (T extends {})

[Typescript] Constraining Types for Anything but null or undefined (T extends {})

时间:2022-12-11 22:23:27浏览次数:40  
标签:Typescript undefined Anything Maybe ts null

export type Maybe<T extends {}> = T | null | undefined;

type tests = [
  // @ts-expect-error
  Maybe<null>,
  // @ts-expect-error
  Maybe<undefined>,

  Maybe<string>,
  Maybe<false>,
  Maybe<0>,
  Maybe<"">
];

 

标签:Typescript,undefined,Anything,Maybe,ts,null
From: https://www.cnblogs.com/Answer1215/p/16974697.html

相关文章