![](/img/trans.png)
[英]How do I correctly type a function that checks whether a key exists in object, and returns the corresponding value?
[英]How to create a type function that checks whether a type is empty object in TypeScript?
是否可以創建一個類型 function IsEmpty
使得:
type a = IsEmpty<{}> // true
type b = IsEmpty<{x: 1}> // never
type IsEmpty<T> = {} extends T ? true : never;
見條件類型
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.