More typesafe NodeSortField definition.

This commit is contained in:
baldo 2022-08-23 21:01:58 +02:00
parent 91690509d3
commit 66fb4e5004
4 changed files with 45 additions and 17 deletions
server/utils

View file

@ -286,12 +286,15 @@ export function filter<E>(
);
}
export function sort<T extends Record<S, unknown>, S extends string>(
entities: T[],
isSortField: TypeGuard<S>,
export function sort<
Type extends { [Key in SortField]: unknown },
SortField extends string
>(
entities: Type[],
isSortField: TypeGuard<SortField>,
restParams: RestParams
): T[] {
const sortField: S | undefined = isSortField(restParams._sortField)
): Type[] {
const sortField: SortField | undefined = isSortField(restParams._sortField)
? restParams._sortField
: undefined;
if (!sortField) {