Type Challenges Judge

Trim

提出詳細

type Trimable = " " | "\n" | "\t" type TrimLeft<S extends string> = S extends `${Trimable}${infer Tail}` ? TrimLeft<Tail>:S; type TrimRight<S extends string> = S extends `${infer Tail}${Trimable}` ? TrimRight<Tail>:S; type Trim<S extends string> = TrimLeft<TrimRight<S>>;
提出日時2022-06-27 12:01:34
問題Trim
ユーザーwaki285
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Trim<'str'>, 'str'>>, Expect<Equal<Trim<' str'>, 'str'>>, Expect<Equal<Trim<' str'>, 'str'>>, Expect<Equal<Trim<'str '>, 'str'>>, Expect<Equal<Trim<' str '>, 'str'>>, Expect<Equal<Trim<' \n\t foo bar \t'>, 'foo bar'>>, Expect<Equal<Trim<''>, ''>>, Expect<Equal<Trim<' \n\t '>, ''>>, ]