shaKY-iota / type-challenges

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

529 - Absolute #24

Open shaKY-iota opened 2 years ago

shaKY-iota commented 2 years ago
// your answers
type Absolute<T extends number | string | bigint> = T extends number | bigint ? Absolute<`${T}`> : T extends `-${infer U}` ? U : T
shaKY-iota commented 2 years ago

https://github.com/type-challenges/type-challenges/issues/2869#issue-980383262

type Absolute<T extends number | string | bigint> = `${T}` extends `-${infer U}` ? U : `${T}`