T
TanStack17mo ago
rare-sapphire

Prevent using <any> in custom sort function

Below custom sort function in isolated file fuzzy-sort.ts works as expected. My question: any pointers on how to replace the <any> type on line 5 with something more strict?
import { compareItems } from "@tanstack/match-sorter-utils";
import { SortingFn, sortingFns } from "@tanstack/react-table";

// Define a custom fuzzy sort function that will sort by rank if the row has ranking information
export const fuzzySort: SortingFn<any> | undefined = (rowA, rowB, columnId) => {
let dir = 0;

// Only sort by rank if the column has ranking information
if (rowA.columnFiltersMeta[columnId]) {
dir = compareItems(
rowA.columnFiltersMeta[columnId]?.itemRank,
rowB.columnFiltersMeta[columnId]?.itemRank,
);
}

// Provide an alphanumeric fallback for when the item ranks are equal
return dir === 0 ? sortingFns.alphanumeric(rowA, rowB, columnId) : dir;
};

export default fuzzySort;
import { compareItems } from "@tanstack/match-sorter-utils";
import { SortingFn, sortingFns } from "@tanstack/react-table";

// Define a custom fuzzy sort function that will sort by rank if the row has ranking information
export const fuzzySort: SortingFn<any> | undefined = (rowA, rowB, columnId) => {
let dir = 0;

// Only sort by rank if the column has ranking information
if (rowA.columnFiltersMeta[columnId]) {
dir = compareItems(
rowA.columnFiltersMeta[columnId]?.itemRank,
rowB.columnFiltersMeta[columnId]?.itemRank,
);
}

// Provide an alphanumeric fallback for when the item ranks are equal
return dir === 0 ? sortingFns.alphanumeric(rowA, rowB, columnId) : dir;
};

export default fuzzySort;
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?