diff --git a/spec/operators/pluck-spec.ts b/spec/operators/pluck-spec.ts index 616b2aae73..d7bdaaddb9 100644 --- a/spec/operators/pluck-spec.ts +++ b/spec/operators/pluck-spec.ts @@ -196,4 +196,14 @@ describe('pluck operator', () => { expectObservable(r).toBe(expected, {y: 'abc'}); expectSubscriptions(a.subscriptions).toBe(asubs); }); + + it('should not break on null values', () => { + const a = cold('--x--|', {x: null}); + const asubs = '^ !'; + const expected = '--y--|'; + + const r = a.pipe(pluck('prop')); + expectObservable(r).toBe(expected, {y: undefined}); + expectSubscriptions(a.subscriptions).toBe(asubs); + }); }); diff --git a/src/internal/operators/pluck.ts b/src/internal/operators/pluck.ts index d566529e9b..96733e5a53 100644 --- a/src/internal/operators/pluck.ts +++ b/src/internal/operators/pluck.ts @@ -51,7 +51,7 @@ export function pluck(...properties: Array): Ope return map((x) => { let currentProp: any = x; for (let i = 0; i < length; i++) { - const p = currentProp[properties[i]]; + const p = currentProp?.[properties[i]]; if (typeof p !== 'undefined') { currentProp = p; } else {