diff --git a/type-definitions/immutable.d.ts b/type-definitions/immutable.d.ts index f343aa06ff..38ecac080a 100644 --- a/type-definitions/immutable.d.ts +++ b/type-definitions/immutable.d.ts @@ -424,7 +424,10 @@ declare namespace Immutable { * @see `Map#update` */ update(index: number, notSetValue: T, updater: (value: T) => T): this; - update(index: number, updater: (value: T | undefined) => T): this; + update( + index: number, + updater: (value: T | undefined) => T | undefined + ): this; update(updater: (value: this) => R): R; /** @@ -1001,7 +1004,7 @@ declare namespace Immutable { * Note: `update(key)` can be used in `withMutations`. */ update(key: K, notSetValue: V, updater: (value: V) => V): this; - update(key: K, updater: (value: V | undefined) => V): this; + update(key: K, updater: (value: V | undefined) => V | undefined): this; update(updater: (value: this) => R): R; /** @@ -5571,7 +5574,7 @@ declare namespace Immutable { function update>( collection: C, key: K, - updater: (value: V | undefined) => V + updater: (value: V | undefined) => V | undefined ): C; function update, NSV>( collection: C, @@ -5598,7 +5601,7 @@ declare namespace Immutable { function update( collection: Array, key: number, - updater: (value: V) => V + updater: (value: V | undefined) => V | undefined ): Array; function update( collection: Array, diff --git a/type-definitions/ts-tests/list.ts b/type-definitions/ts-tests/list.ts index e1738e9d95..1697d62042 100644 --- a/type-definitions/ts-tests/list.ts +++ b/type-definitions/ts-tests/list.ts @@ -265,6 +265,9 @@ import { // $ExpectError List().update(1, 10, (v: number | undefined) => v + 'a'); + // $ExpectType List + List().update(1, (v) => v?.toUpperCase()); + // $ExpectType List update(List(), 0, (v: number | undefined) => 0); diff --git a/type-definitions/ts-tests/map.ts b/type-definitions/ts-tests/map.ts index 3fffffeda3..083c543ab8 100644 --- a/type-definitions/ts-tests/map.ts +++ b/type-definitions/ts-tests/map.ts @@ -176,6 +176,9 @@ import { Map, List } from 'immutable'; // $ExpectError Map().update(1, 10, (v: number | undefined) => v + 'a'); + + // $ExpectType Map + Map().update("noKey", ls => ls?.toUpperCase()); } {