Type Challenges Judge

Trim

提出詳細

type WhiteSpace = " " | "\n" | "\t" type TrimLeft<S extends string> = S extends `${WhiteSpace}${infer Rest}` ? TrimLeft<Rest> : S type TrimRight<S extends string> = S extends `${infer Head}${WhiteSpace}` ? TrimRight<Head> : S type Trim<S extends string> = TrimRight<TrimLeft<S>>
提出日時2023-09-13 14:17:42
問題Trim
ユーザーsankantsu
ステータス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 '>, ''>>, ]