Co-authored-by: Anthony Fu <11247099+antfu@users.noreply.github.com>
This commit is contained in:
github-actions[bot] 2020-11-16 18:38:16 +08:00 committed by GitHub
parent 69a21fdad5
commit 72d338afb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,7 @@
Implement `Replace<S, From, To>` which replace the string `From` with `To` once in the given string `S`
For example
```ts
type replaced = Replace<'types are fun!', 'fun', 'awesome'> // expected to be 'types are awesome!'
```

View File

@ -0,0 +1,9 @@
difficulty: medium
title: Replace
tags: template-string
tsconfig:
ts: 4.1.0-pr-40336-88
author:
github: antfu
name: Anthony Fu

View File

@ -0,0 +1 @@
type Replace<S extends string, From extends string, To extends string> = any

View File

@ -0,0 +1,8 @@
import { 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<'', '', ''>, ''>>,
]