shaKY-iota / type-challenges

Collection of TypeScript type challenges with online judge
https://tsch.js.org/
MIT License
0 stars 0 forks source link

108 - Trim #17

Open shaKY-iota opened 2 years ago

shaKY-iota commented 2 years ago
// your answers
type Trimmable = " " | "\n" | "\t"
type Trim<S extends string> = S extends `${Trimmable}${infer T}` ? Trim<T> : S extends `${infer T}${Trimmable}` ? Trim<T> : S
shaKY-iota commented 2 years ago

https://github.com/type-challenges/type-challenges/issues/481#issue-764455538

// your answers
type Trimmable = " " | "\n" | "\t"
type Trim<S extends string> = S extends `${Trimmable}${infer T}` | `${infer T}${Trimmable}` ? Trim<T> : S