この解答例はChatGPTによって生成されています,正しいかは自己判断で。

BFE.devでのAI解答例 - TypeScript タイプパズル
25. implement UnwrapPromise<T>

解答例:

type UnwrapPromise<T> = T extends Promise<infer U> ? U : Error;

Explanation:

  • T extends Promise<infer U> ? U checks if T is a Promise, and if so, returns its resolved type U.
  • If T is not a Promise, it returns the type Error.