Skip to content

Drop String

题目

Drop the specified chars from a string.

For example:

ts
type Butterfly = DropString<"foobar!", "fb">; // 'ooar!'

解答

ts
type DropString<S, R> = S extends `${infer x}${infer xs}`
  ? R extends `${any}${x}${any}`
    ? DropString<xs, R>
    : `${x}${DropString<xs, R>}`
  : "";

Released under the MIT License.