Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfaee487

Browse files
committed
RenameMapFromObject toMapOf to matchRecordOf
1 parentad0356b commitfaee487

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

‎CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This made `Map` really unusable with TypeScript.
2727
Now the Map is typed like this:
2828

2929
```ts
30-
MapFromObject<{
30+
MapOf<{
3131
length:number;
3232
1:string;
3333
}>
@@ -38,6 +38,7 @@ and the return type of `m.get('length')` is typed as `number`.
3838
The return of`m.get('inexistant')` throw the TypeScript error:
3939

4040
>Argument of type '"inexistant"' is not assignable to parameter of type '1 | "length"
41+
4142
####If you want to keep the old definition
4243

4344
**This is a minor BC for TS users**, so if you want to keep the old definition, you can declare you Map like this:
@@ -59,7 +60,7 @@ type MyMapType = {
5960
const m=Map<MyMapType>({ length:3,1:'one' });
6061
```
6162

62-
Keep in mind that the`MapFromObject` will try to be consistant with the simple TypeScript object, so you can not do this:
63+
Keep in mind that the`MapOf` will try to be consistant with the simple TypeScript object, so you can not do this:
6364

6465
```ts
6566
Map({ a:'a' }).set('b','b');
@@ -77,8 +78,6 @@ Map<{ a?: string }>({ a: 'a' }).delete('a'); // you can only delete an optional
7778

7879
For now, only`get`,`getIn`,`set`,`update`,`delete` and`remove` methods are implemented. All other methods will fallback to the basic`Map` definition. Other method definition will be added later, but as some might be really complex, we prefer the progressive enhancement on the most used functions.
7980

80-
81-
8281
##[4.2.4] - 2023-02-06
8382

8483
- Improve type infererence for from JS by[KSXGitHub](https://github.com/KSXGitHub)[#1927](https://github.com/immutable-js/immutable-js/pull/1927)

‎type-definitions/immutable.d.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ declare namespace Immutable {
812812
functionMap<K,V>(collection?:Iterable<[K,V]>):Map<K,V>;
813813
functionMap<Rextends{[keyinstring|number|symbol]:unknown}>(
814814
obj:R
815-
):MapFromObject<R>;
815+
):MapOf<R>;
816816
functionMap<V>(obj:{[key:string]:V}):Map<string,V>;
817817
functionMap<Kextendsstring|symbol,V>(obj:{[PinK]?:V}):Map<K,V>;
818818

@@ -821,9 +821,8 @@ declare namespace Immutable {
821821
*
822822
*@ignore
823823
*/
824-
interfaceMapFromObject<
825-
Rextends{[keyinstring|number|symbol]:unknown}
826-
>extendsMap<keyofR,R[keyofR]>{
824+
interfaceMapOf<Rextends{[keyinstring|number|symbol]:unknown}>
825+
extendsMap<keyofR,R[keyofR]>{
827826
/**
828827
* Returns the value associated with the provided key, or notSetValue if
829828
* the Collection does not contain this key.
@@ -851,8 +850,8 @@ declare namespace Immutable {
851850
updater:(value:R[K])=>R[K]
852851
): this;
853852

854-
// Possible best type isMapFromObject<Omit<R, K>> but Omit seems to broke other function calls
855-
// and generate recursion error with other methods (update, merge, etc.) until those functions are defined inMapFromObject
853+
// Possible best type isMapOf<Omit<R, K>> but Omit seems to broke other function calls
854+
// and generate recursion error with other methods (update, merge, etc.) until those functions are defined inMapOf
856855
delete<KextendskeyofR>(
857856
key:K
858857
):Extract<R[K],undefined>extendsnever ?never : this;
@@ -865,7 +864,7 @@ declare namespace Immutable {
865864
// https://github.com/immutable-js/immutable-js/issues/1462#issuecomment-584123268
866865

867866
/**@ignore */
868-
typeGetMapType<S>=SextendsMapFromObject<inferT> ?T :S;
867+
typeGetMapType<S>=SextendsMapOf<inferT> ?T :S;
869868

870869
/**@ignore */
871870
typeHead<TextendsReadonlyArray<any>>=Textends[

‎type-definitions/ts-tests/covariance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ let listOfC: List<C> = listOfB;
3434
declarevarmapOfB:Map<string,B>;
3535
letmapOfA:Map<string,A>=mapOfB;
3636

37-
// $ExpectTypeMapFromObject<{ b: B; }>
37+
// $ExpectTypeMapOf<{ b: B; }>
3838
mapOfA=Map({b:newB()});
3939

4040
// $ExpectError

‎type-definitions/ts-tests/map.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{Map,List,MapFromObject}from'immutable';
1+
import{Map,List,MapOf}from'immutable';
22

33
{
44
// #constructor
@@ -18,13 +18,13 @@ import { Map, List, MapFromObject } from 'immutable';
1818
// $ExpectType Map<number, string>
1919
Map(List<[number,string]>([[1,'a']]));
2020

21-
// $ExpectTypeMapFromObject<{ a: number; }>
21+
// $ExpectTypeMapOf<{ a: number; }>
2222
Map({a:1});
2323

24-
// $ExpectTypeMapFromObject<{ a: number; b: string; }>
24+
// $ExpectTypeMapOf<{ a: number; b: string; }>
2525
Map({a:1,b:'b'});
2626

27-
// $ExpectTypeMapFromObject<{ a:MapFromObject<{ b:MapFromObject<{ c: number; }>; }>;}>
27+
// $ExpectTypeMapOf<{ a:MapOf<{ b:MapOf<{ c: number; }>; }>;}>
2828
Map({a:Map({b:Map({c:3})})});
2929

3030
// $ExpectError
@@ -119,7 +119,7 @@ import { Map, List, MapFromObject } from 'immutable';
119119
// $ExpectType number
120120
Map({a:Map({b:Map({c:Map({d:4})})})}).getIn(['a','b','c','d']);
121121

122-
// with a better type, it should be resolved to `number` in the future. `RetrievePathReducer` does not work with anything else thanMapFromObject
122+
// with a better type, it should be resolved to `number` in the future. `RetrievePathReducer` does not work with anything else thanMapOf
123123
// $ExpectType never
124124
Map({a:List([1])}).getIn(['a',0]);
125125
}
@@ -145,10 +145,10 @@ import { Map, List, MapFromObject } from 'immutable';
145145
// $ExpectError
146146
Map({a:1}).set('b','b');
147147

148-
// $ExpectTypeMapFromObject<{ a: number; b?: string | undefined; }>
148+
// $ExpectTypeMapOf<{ a: number; b?: string | undefined; }>
149149
Map<{a:number;b?:string;}>({a:1}).set('b','b');
150150

151-
// $ExpectTypeMapFromObject<{ a: number; b?: string | undefined; }>
151+
// $ExpectTypeMapOf<{ a: number; b?: string | undefined; }>
152152
Map<{a:number;b?:string;}>({a:1}).set('b',undefined);
153153

154154
// $ExpectType number
@@ -161,7 +161,7 @@ import { Map, List, MapFromObject } from 'immutable';
161161
phone:'bar',
162162
});
163163

164-
// $ExpectTypeMapFromObject<{ phone: string | number; }>
164+
// $ExpectTypeMapOf<{ phone: string | number; }>
165165
customer=customer.set('phone',8);
166166
}
167167

@@ -184,10 +184,10 @@ import { Map, List, MapFromObject } from 'immutable';
184184
// $ExpectType never
185185
Map({a:1,b:'b'}).delete('b');
186186

187-
// $ExpectTypeMapFromObject<{ a: number; b?: string | undefined; }>
187+
// $ExpectTypeMapOf<{ a: number; b?: string | undefined; }>
188188
Map<{a:number;b?:string;}>({a:1,b:'b'}).delete('b');
189189

190-
// $ExpectTypeMapFromObject<{ a?: number | undefined; b?: string | undefined; }>
190+
// $ExpectTypeMapOf<{ a?: number | undefined; b?: string | undefined; }>
191191
Map<{a?:number;b?:string;}>({a:1,b:'b'}).remove('b').delete('a');
192192

193193
// $ExpectType number
@@ -278,16 +278,16 @@ import { Map, List, MapFromObject } from 'immutable';
278278
// $ExpectError
279279
Map({a:1,b:'b'}).update('c',(v)=>v);
280280

281-
// $ExpectTypeMapFromObject<{ a: number; b: string; }>
281+
// $ExpectTypeMapOf<{ a: number; b: string; }>
282282
Map({a:1,b:'b'}).update('b',(v)=>v.toUpperCase());
283283

284-
// $ExpectTypeMapFromObject<{ a: number; b: string; }>
284+
// $ExpectTypeMapOf<{ a: number; b: string; }>
285285
Map({a:1,b:'b'}).update('b','NSV',(v)=>v.toUpperCase());
286286

287287
// $ExpectError
288288
Map({a:1,b:'b'}).update((v)=>({a:'a'}));
289289

290-
// $ExpectTypeMapFromObject<{ a: number; b: string; }>
290+
// $ExpectTypeMapOf<{ a: number; b: string; }>
291291
Map({a:1,b:'b'}).update((v)=>v.set('a',2).set('b','B'));
292292

293293
// $ExpectError

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp