Skip to content

Commit

Permalink
fix(data): allow 0 to be a valid key (#3830)
Browse files Browse the repository at this point in the history
Closes #3828
  • Loading branch information
timdeschryver authored Apr 5, 2023
1 parent 4afac00 commit e50126d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions modules/data/spec/actions/entity-action-guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ describe('EntityActionGuard', () => {
action = createAction(1);
expect(guard.mustBeKey(action)).toBe(1);
});

it('should not throw if key is 0', () => {
action = createAction(0);
expect(guard.mustBeKey(action)).toBe(0);
});
});

describe('mustBeKeys', () => {
Expand Down
2 changes: 1 addition & 1 deletion modules/data/src/actions/entity-action-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class EntityActionGuard<T> {
/** Throw if the action payload is not a single, valid key */
mustBeKey(action: EntityAction<string | number>): string | number | never {
const data = this.extractData(action);
if (!data) {
if (data === undefined) {
throw new Error(`should be a single entity key`);
}
if (this.isNotKeyType(data)) {
Expand Down

0 comments on commit e50126d

Please sign in to comment.