Replace
提出詳細
type Replace<S extends string, From extends string, To extends string, Res extends string = ""> = From extends "" ? S : S extends `${From}${infer R}` ? `${Res}${To}${R}` : S extends `${infer L}${infer R}` ? Replace<R, From, To, `${Res}${L}`> : Res
提出日時 | 2023-08-08 16:43:17 |
---|---|
問題 | Replace |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Replace<'foobar', 'bar', 'foo'>, 'foofoo'>>, Expect<Equal<Replace<'foobarbar', 'bar', 'foo'>, 'foofoobar'>>, Expect<Equal<Replace<'foobarbar', '', 'foo'>, 'foobarbar'>>, Expect<Equal<Replace<'foobarbar', 'bar', ''>, 'foobar'>>, Expect<Equal<Replace<'foobarbar', 'bra', 'foo'>, 'foobarbar'>>, Expect<Equal<Replace<'', '', ''>, ''>>, ]