You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a continuation of issue 1466.
In 1842, | undefined was added to the updater function's parameter type, but not the return type. As mentioned in a comment on that issue, the return type also needs to allow undefined. This is specifically needed for cases where no update is applied if the entry does not exist, or where the entry should be deleted.
e.g.
const myMap = Map<string, List<string>>();
const stillMyMap = myMap.update("noKey", ls => ls?.map(x => x + "blah"));
Since myMap doesn't have an entry for "noKey", ls is undefined, and thus the updater returns undefined.
How to reproduce
Run Typescript type-checking on the above example, with strictNullChecks turned on. You will get an error like:
error TS2345: Argument of type '(ls: List<string>|undefined) => List<string>|undefined' is not assignable to parameter of type '(ls: List<string>|undefined) => List<string>'.
Type 'List<string>|undefined' is not assignable to type 'List<string>'.
Type 'undefined' is not assignable to type 'List<string>'.
The text was updated successfully, but these errors were encountered:
What happened
This is a continuation of issue 1466.
In 1842,
| undefined
was added to the updater function's parameter type, but not the return type. As mentioned in a comment on that issue, the return type also needs to allowundefined
. This is specifically needed for cases where no update is applied if the entry does not exist, or where the entry should be deleted.e.g.
Since
myMap
doesn't have an entry for "noKey",ls
isundefined
, and thus the updater returnsundefined
.How to reproduce
Run Typescript type-checking on the above example, with
strictNullChecks
turned on. You will get an error like:The text was updated successfully, but these errors were encountered: