주어진 문자열 S에서 부분 문자열 From을 찾아 모두 To로 교체하는 제네릭 ReplaceAll<S, From, To>을 구현하세요.
type ReplaceAll<S extends string, From extends string, To extends string> =
From extends ''?
S:
S extends `${infer First}${From}${infer Last}`?
`${First}${To}${ReplaceAll<Last,From,To>}`
:S
Replace의 변형 문제이다.
만약 First, Last 를 사용하는 분기가 참인 경우,
ReplaceAll의 제네릭에 ${First}${To}${Last}을 하게 되면 문제가 생긴다.
From에 To가 들어간다면 문제가 꼬이기 때문이다
대부분의 풀이가 비슷했다.