Skip to content
This repository was archived by the owner on Jul 23, 2021. It is now read-only.

Commit f88e4f9

Browse files
authored
TS: update method may return undefined (immutable-js#1933)
1 parent af0a387 commit f88e4f9

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

type-definitions/immutable.d.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,10 @@ declare namespace Immutable {
424424
* @see `Map#update`
425425
*/
426426
update(index: number, notSetValue: T, updater: (value: T) => T): this;
427-
update(index: number, updater: (value: T | undefined) => T): this;
427+
update(
428+
index: number,
429+
updater: (value: T | undefined) => T | undefined
430+
): this;
428431
update<R>(updater: (value: this) => R): R;
429432

430433
/**
@@ -1001,7 +1004,7 @@ declare namespace Immutable {
10011004
* Note: `update(key)` can be used in `withMutations`.
10021005
*/
10031006
update(key: K, notSetValue: V, updater: (value: V) => V): this;
1004-
update(key: K, updater: (value: V | undefined) => V): this;
1007+
update(key: K, updater: (value: V | undefined) => V | undefined): this;
10051008
update<R>(updater: (value: this) => R): R;
10061009

10071010
/**
@@ -5571,7 +5574,7 @@ declare namespace Immutable {
55715574
function update<K, V, C extends Collection<K, V>>(
55725575
collection: C,
55735576
key: K,
5574-
updater: (value: V | undefined) => V
5577+
updater: (value: V | undefined) => V | undefined
55755578
): C;
55765579
function update<K, V, C extends Collection<K, V>, NSV>(
55775580
collection: C,
@@ -5598,7 +5601,7 @@ declare namespace Immutable {
55985601
function update<V>(
55995602
collection: Array<V>,
56005603
key: number,
5601-
updater: (value: V) => V
5604+
updater: (value: V | undefined) => V | undefined
56025605
): Array<V>;
56035606
function update<V, NSV>(
56045607
collection: Array<V>,

type-definitions/ts-tests/list.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ import {
265265
// $ExpectError
266266
List<number>().update(1, 10, (v: number | undefined) => v + 'a');
267267

268+
// $ExpectType List<string>
269+
List<string>().update(1, (v) => v?.toUpperCase());
270+
268271
// $ExpectType List<number>
269272
update(List<number>(), 0, (v: number | undefined) => 0);
270273

type-definitions/ts-tests/map.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ import { Map, List } from 'immutable';
176176

177177
// $ExpectError
178178
Map<number, number>().update(1, 10, (v: number | undefined) => v + 'a');
179+
180+
// $ExpectType Map<string, string>
181+
Map<string, string>().update("noKey", ls => ls?.toUpperCase());
179182
}
180183

181184
{

0 commit comments

Comments
 (0)