This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity posts.
AI solution for TypeScript puzzle on BFE.dev
54. Implement CamelCase<S>
type CamelCase<S> = S extends `${infer T}_${infer U}` ? `${Capitalize<T>}${CamelCase<U>}` : Capitalize<S>;
Explanation:
- We start by checking if the input string
Scontains an underscore_. We do this using a conditional type and the syntax${infer T}_${infer U}which splits the string into two partsTandUseparated by an underscore. - If the input string contains an underscore, we capitalize the first part
TusingCapitalize<T>, and then recursively callCamelCaseon the second partU. - Otherwise, if the input string does not contain an underscore, we simply capitalize the entire string using
Capitalize<S>.