Skip to content

Commit

Permalink
Fix fromJS declaration for greater compatibility (#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Mar 10, 2023
1 parent 14832ca commit 376944d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 5 additions & 5 deletions type-definitions/immutable.d.ts
Expand Up @@ -5161,18 +5161,18 @@ declare namespace Immutable {
* [3]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol
* "The iterable protocol"
*/
function fromJS<JSValue>(
jsValue: JSValue,
reviver?: undefined
): FromJS<JSValue>;
function fromJS(
jsValue: unknown,
reviver: (
reviver?: (
key: string | number,
sequence: Collection.Keyed<string, unknown> | Collection.Indexed<unknown>,
path?: Array<string | number>
) => unknown
): Collection<unknown, unknown>;
function fromJS<JSValue>(
jsValue: JSValue,
reviver?: undefined
): FromJS<JSValue>;

type FromJS<JSValue> = JSValue extends FromJSNoTransform
? JSValue
Expand Down
14 changes: 14 additions & 0 deletions type-definitions/ts-tests/from-js.ts
Expand Up @@ -33,3 +33,17 @@ import { fromJS, List, Map } from 'immutable';
// $ExpectType Map<"a", Map<"b", Map<"c", number>>>
fromJS({a: {b: {c: 0}}});
}

{
// fromJS in an array of function

const create = [(data: any) => data, fromJS][1];

// $ExpectType any
create({ a: 'A' });

const createConst = ([(data: any) => data, fromJS] as const)[1];

// $ExpectType Map<"a", string>
createConst({ a: 'A' });
}

0 comments on commit 376944d

Please sign in to comment.