Replace
提出詳細
type Replace<T extends string, U extends string, V extends string> = U extends '' ? T : T extends `${infer Head}${U}${infer Rest}` ? `${Head}${V}${Rest}` : T
提出日時 | 2023-05-04 22:39:32 |
---|---|
問題 | Replace |
ユーザー | Dowanna |
ステータス | 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<'', '', ''>, ''>>, ]