Skip to content

Commit e50126d

Browse files
fix(data): allow 0 to be a valid key (#3830)
Closes #3828
1 parent 4afac00 commit e50126d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

modules/data/spec/actions/entity-action-guard.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ describe('EntityActionGuard', () => {
114114
action = createAction(1);
115115
expect(guard.mustBeKey(action)).toBe(1);
116116
});
117+
118+
it('should not throw if key is 0', () => {
119+
action = createAction(0);
120+
expect(guard.mustBeKey(action)).toBe(0);
121+
});
117122
});
118123

119124
describe('mustBeKeys', () => {

modules/data/src/actions/entity-action-guard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class EntityActionGuard<T> {
4343
/** Throw if the action payload is not a single, valid key */
4444
mustBeKey(action: EntityAction<string | number>): string | number | never {
4545
const data = this.extractData(action);
46-
if (!data) {
46+
if (data === undefined) {
4747
throw new Error(`should be a single entity key`);
4848
}
4949
if (this.isNotKeyType(data)) {

0 commit comments

Comments
 (0)