react-state-monad 1.0.23 → 1.0.25

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-state-monad",
3
3
  "type": "module",
4
- "version": "1.0.23",
4
+ "version": "1.0.25",
5
5
  "description": "A set of hooks to manage/transform/filter states with monads in React",
6
6
  "keywords": [
7
7
  "maybe",
@@ -29,24 +29,25 @@ export function useFieldState<TOriginal, TField>(
29
29
  * @returns A record where each key is mapped to a new StateObject for the corresponding field.
30
30
  */
31
31
 
32
- export function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>): Record<string, StateObject<TField>> {
32
+ export function useRemapKeysState<TOriginal extends object, TField>(state: StateObject<TOriginal>): Record<keyof TOriginal, StateObject<TField>> {
33
33
  // si state no tiene valor, retornar un invalid
34
34
 
35
35
  if (!state.hasValue) {
36
- return {} as Record<string, StateObject<TField>>;
36
+ return {} as Record<keyof TOriginal, StateObject<TField>>;
37
37
  }
38
38
 
39
39
  if (Array.isArray(state.value)) {
40
40
  console.warn('useRemapKeysState should be used with objects, use useRemapArray for arrays');
41
- return {} as Record<string, StateObject<TField>>;
41
+ return {} as Record<keyof TOriginal, StateObject<TField>>;
42
42
  }
43
43
 
44
- const keys = Object.keys(state.value);
45
-
44
+ const keys = Object.keys(state.value) as (keyof TOriginal)[];
45
+
46
46
  return keys.reduce((acc, key) => {
47
- acc[key] = useFieldState(state, key as ValidFieldFrom<TOriginal, TField>);
48
- return acc;
49
- }, {} as Record<string, StateObject<TField>>);
47
+ acc[key] = useFieldState(state, key as ValidFieldFrom<TOriginal, TField>);
48
+ return acc;
49
+ }
50
+ , {} as Record<keyof TOriginal, StateObject<TField>>);
50
51
  }
51
52
 
52
53