-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve type infererence for Map #1907
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
Conversation
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) |
For the record I tried to address the CI issue in #1908 |
#1908 is merged into main. Can you rebase your branch please ? |
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 |
678584e
to
6b774e3
Compare
rebase done |
? T | ||
: Map<T>); | ||
|
||
interface Map<T> extends IterableMap<keyof T, T[keyof T]> { } |
There was a problem hiding this comment.
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
There was a problem hiding this 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<{ |
There was a problem hiding this comment.
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 🤔 )
v5.0.0-beta has been release and include a lot of fixes for Can you tell me if your issue is resolve ? If not, do you need help on this ? |
Closing as immutable v5 should have solve issue like this |
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:

after:

Even You can nested use it:
