From 96352e08c1ea1f139d86481999429c04a6b075b0 Mon Sep 17 00:00:00 2001 From: Lance Finney Date: Tue, 16 Jun 2020 17:54:27 -0500 Subject: [PATCH] Remove ComparerStr The compare function is used in two places, neither of which expect it to be able to return a string: The first caller (https://github.com/ngrx/platform/blob/master/modules/entity/src/sorted_state_adapter.ts#L174) is the Array prototype sort function, and there it "should return a negative, zero, or positive value, depending on the arguments" (https://www.w3schools.com/js/js_array_sort.asp). The second caller (https://github.com/ngrx/platform/blob/master/modules/entity/src/sorted_state_adapter.ts#L187) does a numerical comparison with the result. Even though an id can be a string, the result of a comparison shouldn't be. This will be a breaking change; any client that returned a string from their comparer will have a compilation failure. Note that any implementation that would not compile because of this would not have been working correctly in the first place. --- modules/data/spec/entity-metadata/entity-definition.spec.ts | 2 +- modules/entity/src/models.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/modules/data/spec/entity-metadata/entity-definition.spec.ts b/modules/data/spec/entity-metadata/entity-definition.spec.ts index 189dc5560d..b42fc8d3d3 100644 --- a/modules/data/spec/entity-metadata/entity-definition.spec.ts +++ b/modules/data/spec/entity-metadata/entity-definition.spec.ts @@ -10,7 +10,7 @@ interface NonIdClass { something: any; } -const sorter = (a: T, b: T) => 'foo'; +const sorter = (a: T, b: T) => 1; const filter = (entities: T[], pattern?: any) => entities; diff --git a/modules/entity/src/models.ts b/modules/entity/src/models.ts index 75eef11e4d..dae9bc3f83 100644 --- a/modules/entity/src/models.ts +++ b/modules/entity/src/models.ts @@ -1,7 +1,4 @@ -export type ComparerStr = (a: T, b: T) => string; -export type ComparerNum = (a: T, b: T) => number; - -export type Comparer = ComparerNum | ComparerStr; +export type Comparer = (a: T, b: T) => number; export type IdSelectorStr = (model: T) => string; export type IdSelectorNum = (model: T) => number;