@types/lodash package and had problems. (version 4.14.104)After upgrading to 4.14.104, the error appears when trying to filter a Dictionary<number> with _.pickBy and reassign to the same variable:
error TS2322: Type 'Partial<Dictionary<number>>' is not assignable to type 'Dictionary<number>'.
Index signatures are incompatible.
Type 'number | undefined' is not assignable to type 'number'.
Type 'undefined' is not assignable to type 'number'.
The code is similar to this:
let mapping: Dictionary<number> = {key1: 5, key2: -3}
mapping = _.pickBy(mapping, v => v > 0)
Ideally, the result of _.pickBy has to be also a Dictionary<T> in this case.
After all, the new object is created which doesn't have some of the keys.
It is not the same as the object that has some of the values changed to undefined.
@andy-ms @bczengel @chrootsu @stepancar @aj-r @Ailrun @e-cloud @thorn0 @jtmthf @DomiR
For now there's a workaround: use Dictionary<number | undefined> everywhere.
let mapping: Dictionary<number | undefined> = {key1: 5, key2: -3}
mapping = _.pickBy(mapping, v => v > 0)
@vvlevykin I think this is fixed since @types/[email protected]. Can you try with the latest version, and close this issue if it works?
Appears to be working, thanks!
@aj-r I'm still seeing this issue in @types/[email protected] with Dictionary<number> as well as dictionaries of types I've defined myself. I tried typescript 2.7.2 and 2.9.2. Is this expected?
Today, I also updated my TypeScript version and other package versions (including @types), and I'm seeing this error :(
I'm looking at the history of pickBy, and it looks like it hasn't changed since February. That said, I'm still reproducing the issue. It looks like this was fixed for pick, but not for pickBy.
I'll see if there's any way to fix pickBy, but there may not be a good solution (without using conditional types, which we can't use because we still need to support TS 2.2).