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 S contains an underscore _. We do this using a conditional type and the syntax ${infer T}_${infer U} which splits the string into two parts T and U separated by an underscore.
  • If the input string contains an underscore, we capitalize the first part T using Capitalize<T>, and then recursively call CamelCase on the second part U.
  • Otherwise, if the input string does not contain an underscore, we simply capitalize the entire string using Capitalize<S>.