diff --git a/spec/operators/pluck-spec.ts b/spec/operators/pluck-spec.ts index 2d710a9264..71ad0bcdb6 100644 --- a/spec/operators/pluck-spec.ts +++ b/spec/operators/pluck-spec.ts @@ -176,4 +176,26 @@ describe('pluck operator', () => { expectObservable(r, unsub).toBe(expected); expectSubscriptions(a.subscriptions).toBe(asubs); }); + + it('should support symbols', () => { + const sym = Symbol('sym'); + + const a = cold('--x--|', {x: {[sym]: 'abc'}}); + const asubs = '^ !'; + const expected = '--y--|'; + + const r = a.pipe(pluck(sym)); + 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 dbe050f25d..543f0d715a 100644 --- a/src/internal/operators/pluck.ts +++ b/src/internal/operators/pluck.ts @@ -56,8 +56,8 @@ function plucker(props: string[], length: number): (x: string) => any { const mapper = (x: string) => { let currentProp = x; for (let i = 0; i < length; i++) { - const p = currentProp[props[i]]; - if (typeof p !== 'undefined') { + const p = currentProp != null ? currentProp[props[i]] : undefined; + if (p !== void 0) { currentProp = p; } else { return undefined;