题目
中文
从字符串中剔除指定字符。
例如:
type Butterfly = DropChar<' b u t t e r f l y ! ', ' '>; // 'butterfly!'
English
Drop a specified char from a string.
For example:
type Butterfly = DropChar<' b u t t e r f l y ! ', ' '>; // 'butterfly!'
答案
type DropChar<
S extends string,
C extends string
> = S extends `${infer L}${infer R}`
? `${C extends L ? '' : L}${DropChar<R, C>}`
: S;
标签:Butterfly,Typescript,DropChar,extends,体操,type,infer
From: https://www.cnblogs.com/laggage/p/type-challenge-drop-char.html