diff --git a/type-definitions/flow-tests/immutable-flow.js b/type-definitions/flow-tests/immutable-flow.js index 4b32d64341..c203962052 100644 --- a/type-definitions/flow-tests/immutable-flow.js +++ b/type-definitions/flow-tests/immutable-flow.js @@ -130,6 +130,16 @@ var item: number = numberList.get(4); var nullableItem: ?number = numberList.get(4); var itemOrDefault: number = numberList.get(4, 10); +// $FlowExpectedError[incompatible-type] +var item: number = numberList.first(); +// $FlowExpectedError[incompatible-type] +var func: () => number = () => numberList.first(); + +// $FlowExpectedError[incompatible-type] +var item: number = numberList.last(); +// $FlowExpectedError[incompatible-type] +var func: () => number = () => numberList.last(); + numberList = List().insert(0, 0); numberOrStringList = List.of(0).insert(1, 'a'); // $FlowExpectedError[incompatible-call] diff --git a/type-definitions/immutable.d.ts b/type-definitions/immutable.d.ts index dc2b24547c..3fd60eecb9 100644 --- a/type-definitions/immutable.d.ts +++ b/type-definitions/immutable.d.ts @@ -4208,7 +4208,8 @@ declare namespace 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(notSetValue: NSV): V | NSV; + first(): V | undefined; /** * In case the `Collection` is not empty returns the last element of the @@ -4216,7 +4217,8 @@ declare namespace 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(notSetValue: NSV): V | NSV; + last(): V | undefined; // Reading deep values diff --git a/type-definitions/immutable.js.flow b/type-definitions/immutable.js.flow index 67a496f29c..901960b873 100644 --- a/type-definitions/immutable.js.flow +++ b/type-definitions/immutable.js.flow @@ -76,8 +76,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 | void; + first(notSetValue: NSV): V | NSV; + last(): V | void; + last(notSetValue: NSV): V | NSV; hasIn(keyPath: Iterable): boolean; diff --git a/type-definitions/ts-tests/list.ts b/type-definitions/ts-tests/list.ts index 1697d62042..08ea834568 100644 --- a/type-definitions/ts-tests/list.ts +++ b/type-definitions/ts-tests/list.ts @@ -76,6 +76,26 @@ import { get(List(), 4, 'a'); } +{ + // #first + + // $ExpectType number | undefined + List().first(); + + // $ExpectError + (): number => List().first(); +} + +{ + // #last + + // $ExpectType number | undefined + List().last(); + + // $ExpectError + (): number => List().last(); +} + { // #set