この解答例はChatGPTによって生成されています,正しいかは自己判断で。 皆の投稿からも解答例が見つかるかもしれませんよ。
BFE.devでのAI解答例 - TypeScript タイプパズル
59. implement MapStringUnionToObjectUnion<U>
type MapStringUnionToObjectUnion<U extends string> = U extends never ? never : { value: U };
Explanation:
The MapStringUnionToObjectUnion
takes a string union as its generic type parameter. We can use the conditional type to check if the type extends never
. If it does, we return never
to indicate there are no possible object unions. If it does not, we return an object type with a single property value
which has a value of the original input type. This object type becomes one of the possible object unions in the resulting type.