Skip to content

Fix fromJS declaration for greater compatibility #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions type-definitions/immutable.d.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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' });
}