type CompareType = number | string | BigInt ; export function sortBy < T extends CompareType > ( i , kFn ? ) ; export function sortBy < T extends Exclude < any , CompareType > > ( i , kFn ) ; param arr param kFn export function sortBy < T > ( arr , kFn = ( v ) => ( v as unknown ) as CompareType ) { return [ ... arr ] . sort ( ( a , b ) => { const ak = kFn ( a ) ; const bk = kFn ( b ) ; if ( ak === bk ) { return 0 ; } if ( ak > bk ) { return 1 ; } return - 1 ; } ) ; }