From a1282dde3b3dedc22d79dd52dd830d3e45d3beb9 Mon Sep 17 00:00:00 2001 From: August Lilleaas Date: Tue, 27 Nov 2018 18:14:11 +0100 Subject: [PATCH] Add separate types for Collection first()/last() with zero arguments When the type is `first(notSetValue?: NSV): V | NSV`, the type of the return value will always be `V | NSV` and you will have to handle the possibility of the return value as being both of type V and NSV. When you call `first` without specifying the type, it will default to the type {}. This patch changes the type of `first` without a type argument to be that type or undefined, instead of that type or NSV, which defaults to `{}` when not specified. --- type-definitions/Immutable.d.ts | 6 ++++-- type-definitions/immutable.js.flow | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/type-definitions/Immutable.d.ts b/type-definitions/Immutable.d.ts index baae41d011..05f572b4d8 100644 --- a/type-definitions/Immutable.d.ts +++ b/type-definitions/Immutable.d.ts @@ -3878,7 +3878,8 @@ declare module Immutable { * In case the `Collection` is empty returns the optional default * value if provided, if no default value is provided returns undefined. */ - first(notSetValue?: NSV): V | NSV; + first(): V | undefined; + first(notSetValue: NSV): V | NSV; /** * In case the `Collection` is not empty returns the last element of the @@ -3886,7 +3887,8 @@ declare module Immutable { * In case the `Collection` is empty returns the optional default * value if provided, if no default value is provided returns undefined. */ - last(notSetValue?: NSV): V | NSV; + last(): V | undefined; + last(notSetValue: NSV): V | NSV; // Reading deep values diff --git a/type-definitions/immutable.js.flow b/type-definitions/immutable.js.flow index 2b37f41437..c4aa6d191a 100644 --- a/type-definitions/immutable.js.flow +++ b/type-definitions/immutable.js.flow @@ -63,8 +63,10 @@ declare class _Collection implements ValueObject { has(key: K): boolean; includes(value: V): boolean; contains(value: V): boolean; - first(notSetValue?: NSV): V | NSV; - last(notSetValue?: NSV): V | NSV; + first(): V | undefined; + first(notSetValue: NSV): V | NSV; + last(): V | undefined; + last(notSetValue: NSV): V | NSV; hasIn(keyPath: Iterable): boolean;