This restriction isn't used in DataTable.svelte and it wouldn't be a problem to use number as return type instead.
Doing so would give consumers of this library an easier way to write comparison functions, for example when sorting by Date: You could then write something like: (a:Date, b:Date) => a.getTime() - b.getTime() instead of having to write Math.max(Math.min(a.getTime()-b.getTime(), 1), -1). This would also improve performance slightly.
The expected return type for sorting rows in a DataTable is currently: https://github.com/carbon-design-system/carbon-components-svelte/blob/21b1d78d8ebda608d78c1ab22833c36138f9ef3c/types/DataTable/DataTable.svelte.d.ts#L12
This restriction isn't used in DataTable.svelte and it wouldn't be a problem to use
number
as return type instead.Doing so would give consumers of this library an easier way to write comparison functions, for example when sorting by Date: You could then write something like:
(a:Date, b:Date) => a.getTime() - b.getTime()
instead of having to writeMath.max(Math.min(a.getTime()-b.getTime(), 1), -1)
. This would also improve performance slightly.