Type Challenges Judge

Trim

提出詳細

type TrimTarget = " " | "\n" | "\t" type Trim<T extends string> = T extends `${TrimTarget}${infer Tail}` ? Trim<Tail> : T extends `${infer Head}${TrimTarget}` ? Trim<Head> : T
提出日時2023-05-03 04:53:13
問題Trim
ユーザーDowanna
ステータス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 '>, ''>>, ]