实现 ReplaceAll<S, From, To>
将一个字符串 S
中的所有子字符串 From
替换为 To
。
例如
type replaced = ReplaceAll<'t y p e s', ' ', ''> // 期望是 'types'
Implement ReplaceAll<S, From, To>
which replace the all the substring From
with To
in the given string S
For example
type replaced = ReplaceAll<'t y p e s', ' ', ''> // expected to be 'types'
type ReplaceAll<S extends string, From extends string, To extends string> = From extends '' ? S : (S extends `${infer L}${From}${infer R}` ? `${ReplaceAll<L, From, To>}${To}${ReplaceAll<R, From, To>}` : S);
在线演示