Skip to content
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

Improve type infererence for Map #1907

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

A0150315
Copy link

@A0150315 A0150315 commented Jun 24, 2022

With this pull request, Map(T) will be return type smoothly.

I think this PR is very important cause this is the first step to correct the type inference of Map

before:
image

after:
image

Even You can nested use it:
image

@jdeniau
Copy link
Member

jdeniau commented Jun 24, 2022

Hi,

The fact that you did removed 2 of 3 functions is a problem because Map accept other forms like this :

Map([['a', 'A'], ['b', 'B']])

For the record, #1841 tries to improve greatly the Map type (but I do not have time to work on this now, and your PR might be merge independantly)

@jdeniau
Copy link
Member

jdeniau commented Jun 24, 2022

For the record I tried to address the CI issue in #1908

@jdeniau
Copy link
Member

jdeniau commented Jun 24, 2022

#1908 is merged into main. Can you rebase your branch please ?

@A0150315
Copy link
Author

A0150315 commented Jun 27, 2022

Hi,

The fact that you did removed 2 of 3 functions is a problem because Map accept other forms like this :

Map([['a', 'A'], ['b', 'B']])

For the record, #1841 tries to improve greatly the Map type (but I do not have time to work on this now, and your PR might be merge independantly)

oh~ is my bad, i don't know this usage, i'll try to fix it

i had viewed the #1841,it is a really big PR,i considered small PR will be easy to merge,so maybe i will create more PR in the future to improve type inference

@A0150315 A0150315 force-pushed the patch-2 branch 3 times, most recently from 678584e to 6b774e3 Compare June 27, 2022 02:26
@A0150315
Copy link
Author

#1908 is merged into main. Can you rebase your branch please ?

rebase done

? T
: Map<T>);

interface Map<T> extends IterableMap<keyof T, T[keyof T]> { }
Copy link
Author

@A0150315 A0150315 Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was necessary to infer value from key from Object instead of <K,V> cause <K,V> will broke relation with K and V,then we can infer key and value by T in the future

Copy link
Member

@jdeniau jdeniau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the response delay !

Can you add at least one test that validate your change and avoid regression in https://github.com/immutable-js/immutable-js/blob/main/type-definitions/ts-tests/map.ts ?

function Map<K extends string | symbol, V>(obj: { [P in K]?: V }): Map<K, V>;

interface Map<K, V> extends Collection.Keyed<K, V> {
function Map<T extends Array<[string | number | symbol, unknown]>>(collection: T): Map<{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You changed from Iterable to Array. Can you make it back to iterable ? A List is iterable, but not an Array for example (but I'm not that sure as there is a test that validate this case 🤔 )

@jdeniau
Copy link
Member

jdeniau commented Sep 25, 2023

v5.0.0-beta has been release and include a lot of fixes for Map type. (PR here)

Can you tell me if your issue is resolve ? If not, do you need help on this ?

@jdeniau jdeniau added typescript awaiting-response Awaiting response from creator. Can't fix without it. labels Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-response Awaiting response from creator. Can't fix without it. typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants