This is a sorting algorithm implemented using only TypeScript types. Note: requires TypeScript 4.7.0 or newer.
Try the live demo in the TypeScript Playground.
type SortedThings = Sorted<[0, 8, -7, -3e7, 1337, 5, 3, 4]>
// SortedThings has type of [-30000000, -7, 0, 3, 4, 5, 8, 1337]
Q. Does this actually work?
A. Yes, but only for tuples up to around 90 elements long, containing integers between -1021 and 1021.
Q. Why would I ever want to use this?
A. Uhh... science?
This implementation uses GreaterThan
from type-plus to perform comparisons between numbers.