I saw this commit and I'm wondering why pluck is deprecated? I couldn't find any issue where this is discussed.
By the logic behind the explanation about using optional chaining, this means that you can easily deprecate lot's of other simple operators like startWith, endWith, timestamp and so on, because it's always possible to use pipe + something in case of these. I just wonder what's the reason behind deprecating this operator.
pluck('prop') is a shorthand for map(x => x.prop), the main advantage to using pluck was the path traversal safety, meaning you can do
pluck('foo', 'bar', 'baz')
and this would be fine even if the emitted value didn't have a foo property. Contrast this with
map(x => x.foo.bar.baz) which will error if the emitted value doesn't have a foo property
With optional chaining this advantage is no longer true since you can now do
map(x => x?.foo?.bar?.baz)
And it will be as safe as the pluck usage. Note that having proper TypeScript typing for pluck is quite complex and not as robust as the map usage which is a major reason to prefer the map method
FWIW, deprecated parts of the API won't necessarily be removed in the very next major version of the library. ATM, one of the things on which we are working is improving the deprecation messages to make them easier to understand and to include links to the documentation to explain what is being deprecated and when it's likely to be removed. IMO, pluck won't be removed from the API until version 8 or later.
Thanks for the clarifications @kolodny, @cartant. I like this operator and I use it a lot because it's easier (and more clean IMO) to write pluck than map.
Most helpful comment
pluck('prop')is a shorthand formap(x => x.prop), the main advantage to using pluck was the path traversal safety, meaning you can doand this would be fine even if the emitted value didn't have a
fooproperty. Contrast this withmap(x => x.foo.bar.baz)which will error if the emitted value doesn't have afoopropertyWith optional chaining this advantage is no longer true since you can now do
And it will be as safe as the
pluckusage. Note that having proper TypeScript typing for pluck is quite complex and not as robust as the map usage which is a major reason to prefer themapmethod