File tree Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Expand file tree Collapse file tree 2 files changed +14
-11
lines changed Original file line number Diff line number Diff line change 1
1
import { PayloadAction } from '../createAction'
2
2
3
- export type ComparerStr < T > = ( a : T , b : T ) => string
4
- export type ComparerNum < T > = ( a : T , b : T ) => number
5
-
6
3
/**
7
4
* @alpha
8
5
*/
9
- export type Comparer < T > = ComparerNum < T > | ComparerStr < T >
6
+ export type EntityId = number | string
10
7
11
- export type IdSelectorStr < T > = ( model : T ) => string
12
- export type IdSelectorNum < T > = ( model : T ) => number
8
+ /**
9
+ * @alpha
10
+ */
11
+ export type Comparer < T > = ( a : T , b : T ) => EntityId
13
12
14
13
/**
15
14
* @alpha
16
15
*/
17
- export type IdSelector < T > = IdSelectorStr < T > | IdSelectorNum < T >
16
+ export type IdSelector < T > = ( model : T ) => EntityId
18
17
18
+ /**
19
+ * @alpha
20
+ */
19
21
export interface DictionaryNum < T > {
20
22
[ id : number ] : T | undefined
21
23
}
@@ -47,13 +49,16 @@ export type Update<T> = UpdateStr<T> | UpdateNum<T>
47
49
*/
48
50
export type EntityMap < T > = ( entity : T ) => T
49
51
52
+ /**
53
+ * @alpha
54
+ */
50
55
export type TypeOrPayloadAction < T > = T | PayloadAction < T >
51
56
52
57
/**
53
58
* @alpha
54
59
*/
55
60
export interface EntityState < T > {
56
- ids : string [ ] | number [ ]
61
+ ids : EntityId [ ]
57
62
entities : Dictionary < T >
58
63
}
59
64
Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ export function createUnsortedStateAdapter<T>(selectId: IdSelector<T>): any {
57
57
} )
58
58
59
59
if ( didMutate ) {
60
- // Work around TS not letting us call array methods if it's not a single known type
61
- const ids = state . ids as string [ ]
62
- state . ids = ids . filter ( ( id : any ) => id in state . entities )
60
+ state . ids = state . ids . filter ( id => id in state . entities )
63
61
}
64
62
}
65
63
You can’t perform that action at this time.
0 commit comments