@gateweb/react-utils 1.14.3 → 1.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -381,29 +381,30 @@ declare const isEqual: (value1: unknown, value2: unknown) => boolean;
381
381
  * // => { A: 'a', B: 'b' }
382
382
  */
383
383
  declare const extractEnumLikeObject: <T extends Record<string, { [P in K]: any; }>, K extends string>(enumObject: T, valueKey: K) => { [key in keyof T]: T[key][K]; };
384
- type EnumMap<T extends Record<string, any>, VK extends keyof T[keyof T] & string> = {
385
- [K in keyof T]: T[K][VK];
384
+ type EnumMap<T extends Record<string, any>, VK extends string> = {
385
+ [K in keyof T]: T[K] extends Record<VK, infer R> ? R : never;
386
386
  };
387
387
  type NormalList<T extends Record<string, any>> = Array<{
388
388
  key: string;
389
389
  } & T[keyof T]>;
390
+ type ValueAtKey<T extends Record<string, any>, K extends string> = T[keyof T] extends infer U ? U extends Record<K, infer R> ? R : never : never;
390
391
  type ScenesList<T extends Record<string, {
391
392
  scenes: Record<string, Record<string, any>>;
392
- }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string> = Array<{
393
+ }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string> = Array<{
393
394
  key: string;
394
- value: T[keyof T][VK];
395
+ value: ValueAtKey<T, VK>;
395
396
  } & T[keyof T]['scenes'][Scene]>;
396
- type NormalReturn<T extends Record<string, any>, VK extends keyof T[keyof T] & string> = {
397
+ type NormalReturn<T extends Record<string, any>, VK extends string> = {
397
398
  Enum: EnumMap<T, VK>;
398
399
  List: NormalList<T>;
399
- getLabel: (value: T[keyof T][VK]) => string;
400
+ getLabel: (value: ValueAtKey<T, VK>) => string;
400
401
  };
401
402
  type ScenesReturn<T extends Record<string, {
402
403
  scenes: Record<string, Record<string, any>>;
403
- }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string> = {
404
+ }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string> = {
404
405
  Enum: EnumMap<T, VK>;
405
406
  List: ScenesList<T, Scene, VK>;
406
- getLabel: (value: T[keyof T][VK]) => string;
407
+ getLabel: (value: ValueAtKey<T, VK>) => string;
407
408
  };
408
409
  type AsNamed<R, N extends string> = {
409
410
  [K in keyof R as K extends 'Enum' ? `Enum${N}` : K extends 'List' ? `${N}List` : K extends 'getLabel' ? `get${N}Label` : never]: R[K];
@@ -504,18 +505,18 @@ type ScenesOptions<Scene extends string, VK extends string> = SceneOption<Scene>
504
505
  * ```
505
506
  *
506
507
  */
507
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
508
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
508
509
  scenes: Record<string, Record<string, any>>;
509
- }>, N extends string, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string>(obj: T, options: ScenesNamedOptions<N, Scene, VK>): AsNamed<ScenesReturn<T, Scene, VK>, N>;
510
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
510
+ }>, N extends string, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string = 'value'>(obj: T, options: ScenesNamedOptions<N, Scene, VK>): AsNamed<ScenesReturn<T, Scene, VK>, N>;
511
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
511
512
  scenes: Record<string, Record<string, any>>;
512
- }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string>(obj: T, options: ScenesOptions<Scene, VK>): ScenesReturn<T, Scene, VK>;
513
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
513
+ }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string = 'value'>(obj: T, options: ScenesOptions<Scene, VK>): ScenesReturn<T, Scene, VK>;
514
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
514
515
  label: string;
515
- }>, N extends string, VK extends keyof T[keyof T] & string>(obj: T, options: NormalNamedOptions<N, VK>): AsNamed<NormalReturn<T, VK>, N>;
516
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
516
+ }>, N extends string, VK extends string = 'value'>(obj: T, options: NormalNamedOptions<N, VK>): AsNamed<NormalReturn<T, VK>, N>;
517
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
517
518
  label: string;
518
- }>, VK extends keyof T[keyof T] & string>(obj: T, options?: NormalOptions<VK>): NormalReturn<T, VK>;
519
+ }>, VK extends string = 'value'>(obj: T, options?: NormalOptions<VK>): NormalReturn<T, VK>;
519
520
 
520
521
  /**
521
522
  * simulate a fake api request
@@ -381,29 +381,30 @@ declare const isEqual: (value1: unknown, value2: unknown) => boolean;
381
381
  * // => { A: 'a', B: 'b' }
382
382
  */
383
383
  declare const extractEnumLikeObject: <T extends Record<string, { [P in K]: any; }>, K extends string>(enumObject: T, valueKey: K) => { [key in keyof T]: T[key][K]; };
384
- type EnumMap<T extends Record<string, any>, VK extends keyof T[keyof T] & string> = {
385
- [K in keyof T]: T[K][VK];
384
+ type EnumMap<T extends Record<string, any>, VK extends string> = {
385
+ [K in keyof T]: T[K] extends Record<VK, infer R> ? R : never;
386
386
  };
387
387
  type NormalList<T extends Record<string, any>> = Array<{
388
388
  key: string;
389
389
  } & T[keyof T]>;
390
+ type ValueAtKey<T extends Record<string, any>, K extends string> = T[keyof T] extends infer U ? U extends Record<K, infer R> ? R : never : never;
390
391
  type ScenesList<T extends Record<string, {
391
392
  scenes: Record<string, Record<string, any>>;
392
- }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string> = Array<{
393
+ }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string> = Array<{
393
394
  key: string;
394
- value: T[keyof T][VK];
395
+ value: ValueAtKey<T, VK>;
395
396
  } & T[keyof T]['scenes'][Scene]>;
396
- type NormalReturn<T extends Record<string, any>, VK extends keyof T[keyof T] & string> = {
397
+ type NormalReturn<T extends Record<string, any>, VK extends string> = {
397
398
  Enum: EnumMap<T, VK>;
398
399
  List: NormalList<T>;
399
- getLabel: (value: T[keyof T][VK]) => string;
400
+ getLabel: (value: ValueAtKey<T, VK>) => string;
400
401
  };
401
402
  type ScenesReturn<T extends Record<string, {
402
403
  scenes: Record<string, Record<string, any>>;
403
- }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string> = {
404
+ }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string> = {
404
405
  Enum: EnumMap<T, VK>;
405
406
  List: ScenesList<T, Scene, VK>;
406
- getLabel: (value: T[keyof T][VK]) => string;
407
+ getLabel: (value: ValueAtKey<T, VK>) => string;
407
408
  };
408
409
  type AsNamed<R, N extends string> = {
409
410
  [K in keyof R as K extends 'Enum' ? `Enum${N}` : K extends 'List' ? `${N}List` : K extends 'getLabel' ? `get${N}Label` : never]: R[K];
@@ -504,18 +505,18 @@ type ScenesOptions<Scene extends string, VK extends string> = SceneOption<Scene>
504
505
  * ```
505
506
  *
506
507
  */
507
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
508
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
508
509
  scenes: Record<string, Record<string, any>>;
509
- }>, N extends string, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string>(obj: T, options: ScenesNamedOptions<N, Scene, VK>): AsNamed<ScenesReturn<T, Scene, VK>, N>;
510
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
510
+ }>, N extends string, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string = 'value'>(obj: T, options: ScenesNamedOptions<N, Scene, VK>): AsNamed<ScenesReturn<T, Scene, VK>, N>;
511
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
511
512
  scenes: Record<string, Record<string, any>>;
512
- }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends keyof T[keyof T] & string>(obj: T, options: ScenesOptions<Scene, VK>): ScenesReturn<T, Scene, VK>;
513
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
513
+ }>, Scene extends keyof T[keyof T]['scenes'] & string, VK extends string = 'value'>(obj: T, options: ScenesOptions<Scene, VK>): ScenesReturn<T, Scene, VK>;
514
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
514
515
  label: string;
515
- }>, N extends string, VK extends keyof T[keyof T] & string>(obj: T, options: NormalNamedOptions<N, VK>): AsNamed<NormalReturn<T, VK>, N>;
516
- declare function createEnumLikeObject<T extends Record<string, Record<VK, any> & {
516
+ }>, N extends string, VK extends string = 'value'>(obj: T, options: NormalNamedOptions<N, VK>): AsNamed<NormalReturn<T, VK>, N>;
517
+ declare function createEnumLikeObject<T extends Record<string, Record<string, any> & {
517
518
  label: string;
518
- }>, VK extends keyof T[keyof T] & string>(obj: T, options?: NormalOptions<VK>): NormalReturn<T, VK>;
519
+ }>, VK extends string = 'value'>(obj: T, options?: NormalOptions<VK>): NormalReturn<T, VK>;
519
520
 
520
521
  /**
521
522
  * simulate a fake api request
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gateweb/react-utils",
3
- "version": "1.14.3",
3
+ "version": "1.14.4",
4
4
  "description": "React Utils for GateWeb",
5
5
  "homepage": "https://github.com/GatewebSolutions/react-utils",
6
6
  "files": [