この解答例はChatGPTによって生成されています,正しいかは自己判断で。 皆の投稿からも解答例が見つかるかもしれませんよ。
BFE.devでのAI解答例 - TypeScript タイプパズル
28. implement IsEmptyType<T>
type IsEmptyType<T> = keyof T extends never ? true : false;
Explanation:
keyof T
returns the union of all possible keys of T.never
is an empty type, so ifkeyof T
evaluates tonever
, it means T has no possible keys, thus it is an empty type.- We use a conditional type to check if
keyof T
extendsnever
. If it does, it means T is an empty type, and we returntrue
. Otherwise, we returnfalse
.