Skip to content

Commit

Permalink
fix(entity): remove incorrect ComparerStr type (#2584)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

The compare function is used in two places, neither of which expect it to be able to return a string:
The first caller is the Array prototype sort function, and there it "should return a negative, zero, or positive value, depending on the arguments".
The second caller does a numerical comparison with the result.

Even though an id can be a string, the result of a comparison shouldn't be.

BEFORE:

The sortComparer types allow for a string to be returned

AFTER:

The sortComparer types only allow a number to be returned
  • Loading branch information
LMFinney authored Jun 18, 2020
1 parent e3b178d commit 4796c97
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface NonIdClass {
something: any;
}

const sorter = <T>(a: T, b: T) => 'foo';
const sorter = <T>(a: T, b: T) => 1;

const filter = <T>(entities: T[], pattern?: any) => entities;

Expand Down
5 changes: 1 addition & 4 deletions modules/entity/src/models.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
export type ComparerStr<T> = (a: T, b: T) => string;
export type ComparerNum<T> = (a: T, b: T) => number;

export type Comparer<T> = ComparerNum<T> | ComparerStr<T>;
export type Comparer<T> = (a: T, b: T) => number;

export type IdSelectorStr<T> = (model: T) => string;
export type IdSelectorNum<T> = (model: T) => number;
Expand Down

0 comments on commit 4796c97

Please sign in to comment.