@eslint-react/shared 1.40.2-next.0 → 1.40.2-next.1

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.
package/dist/index.d.mts CHANGED
@@ -688,6 +688,146 @@ declare global {
688
688
  }
689
689
  }
690
690
 
691
+ /**
692
+ Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
693
+
694
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
695
+
696
+ @example
697
+ ```
698
+ import type {UnionToIntersection} from 'type-fest';
699
+
700
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
701
+
702
+ type Intersection = UnionToIntersection<Union>;
703
+ //=> {the(): void; great(arg: string): void; escape: boolean};
704
+ ```
705
+
706
+ A more applicable example which could make its way into your library code follows.
707
+
708
+ @example
709
+ ```
710
+ import type {UnionToIntersection} from 'type-fest';
711
+
712
+ class CommandOne {
713
+ commands: {
714
+ a1: () => undefined,
715
+ b1: () => undefined,
716
+ }
717
+ }
718
+
719
+ class CommandTwo {
720
+ commands: {
721
+ a2: (argA: string) => undefined,
722
+ b2: (argB: string) => undefined,
723
+ }
724
+ }
725
+
726
+ const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
727
+ type Union = typeof union;
728
+ //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
729
+
730
+ type Intersection = UnionToIntersection<Union>;
731
+ //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
732
+ ```
733
+
734
+ @category Type
735
+ */
736
+ type UnionToIntersection<Union> = (
737
+ // `extends unknown` is always going to be the case and is used to convert the
738
+ // `Union` into a [distributive conditional
739
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
740
+ Union extends unknown
741
+ // The union type is used as the only argument to a function since the union
742
+ // of function arguments is an intersection.
743
+ ? (distributedUnion: Union) => void
744
+ // This won't happen.
745
+ : never
746
+ // Infer the `Intersection` type since TypeScript represents the positional
747
+ // arguments of unions of functions as an intersection of the union.
748
+ ) extends ((mergedIntersection: infer Intersection) => void)
749
+ // The `& Union` is to allow indexing by the resulting type
750
+ ? Intersection & Union
751
+ : never;
752
+
753
+ /**
754
+ Create a union of all keys from a given type, even those exclusive to specific union members.
755
+
756
+ Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
757
+
758
+ @link https://stackoverflow.com/a/49402091
759
+
760
+ @example
761
+ ```
762
+ import type {KeysOfUnion} from 'type-fest';
763
+
764
+ type A = {
765
+ common: string;
766
+ a: number;
767
+ };
768
+
769
+ type B = {
770
+ common: string;
771
+ b: string;
772
+ };
773
+
774
+ type C = {
775
+ common: string;
776
+ c: boolean;
777
+ };
778
+
779
+ type Union = A | B | C;
780
+
781
+ type CommonKeys = keyof Union;
782
+ //=> 'common'
783
+
784
+ type AllKeys = KeysOfUnion<Union>;
785
+ //=> 'common' | 'a' | 'b' | 'c'
786
+ ```
787
+
788
+ @category Object
789
+ */
790
+ type KeysOfUnion<ObjectType> =
791
+ // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
792
+ keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
793
+
794
+ /**
795
+ Extract all optional keys from the given type.
796
+
797
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
798
+
799
+ @example
800
+ ```
801
+ import type {OptionalKeysOf, Except} from 'type-fest';
802
+
803
+ interface User {
804
+ name: string;
805
+ surname: string;
806
+
807
+ luckyNumber?: number;
808
+ }
809
+
810
+ const REMOVE_FIELD = Symbol('remove field symbol');
811
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
812
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
813
+ };
814
+
815
+ const update1: UpdateOperation<User> = {
816
+ name: 'Alice'
817
+ };
818
+
819
+ const update2: UpdateOperation<User> = {
820
+ name: 'Bob',
821
+ luckyNumber: REMOVE_FIELD
822
+ };
823
+ ```
824
+
825
+ @category Utilities
826
+ */
827
+ type OptionalKeysOf<BaseType extends object> = KeysOfUnion<{
828
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
829
+ }>;
830
+
691
831
  /**
692
832
  Extract all required keys from the given type.
693
833
 
@@ -712,11 +852,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
712
852
 
713
853
  @category Utilities
714
854
  */
715
- type RequiredKeysOf<BaseType extends object> = Exclude<{
716
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
717
- ? Key
718
- : never
719
- }[keyof BaseType], undefined>;
855
+ type RequiredKeysOf<BaseType extends object> =
856
+ BaseType extends unknown // For distributing `BaseType`
857
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
858
+ : never; // Should never happen
720
859
 
721
860
  /**
722
861
  Returns a boolean for whether the given type is `never`.
@@ -1092,45 +1231,6 @@ type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
1092
1231
  IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
1093
1232
  );
1094
1233
 
1095
- /**
1096
- Extract all optional keys from the given type.
1097
-
1098
- This is useful when you want to create a new type that contains different type values for the optional keys only.
1099
-
1100
- @example
1101
- ```
1102
- import type {OptionalKeysOf, Except} from 'type-fest';
1103
-
1104
- interface User {
1105
- name: string;
1106
- surname: string;
1107
-
1108
- luckyNumber?: number;
1109
- }
1110
-
1111
- const REMOVE_FIELD = Symbol('remove field symbol');
1112
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
1113
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
1114
- };
1115
-
1116
- const update1: UpdateOperation<User> = {
1117
- name: 'Alice'
1118
- };
1119
-
1120
- const update2: UpdateOperation<User> = {
1121
- name: 'Bob',
1122
- luckyNumber: REMOVE_FIELD
1123
- };
1124
- ```
1125
-
1126
- @category Utilities
1127
- */
1128
- type OptionalKeysOf<BaseType extends object> = Exclude<{
1129
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
1130
- ? never
1131
- : Key
1132
- }[keyof BaseType], undefined>;
1133
-
1134
1234
  /**
1135
1235
  Matches any primitive, `void`, `Date`, or `RegExp` value.
1136
1236
  */
@@ -1197,7 +1297,11 @@ type ApplyDefaultOptions<
1197
1297
  IfNever<SpecifiedOptions, Defaults,
1198
1298
  Simplify<Merge<Defaults, {
1199
1299
  [Key in keyof SpecifiedOptions
1200
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
1300
+ as Key extends OptionalKeysOf<Options>
1301
+ ? Extract<SpecifiedOptions[Key], undefined> extends never
1302
+ ? Key
1303
+ : never
1304
+ : Key
1201
1305
  ]: SpecifiedOptions[Key]
1202
1306
  }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
1203
1307
  >>;
package/dist/index.d.ts CHANGED
@@ -688,6 +688,146 @@ declare global {
688
688
  }
689
689
  }
690
690
 
691
+ /**
692
+ Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
693
+
694
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
695
+
696
+ @example
697
+ ```
698
+ import type {UnionToIntersection} from 'type-fest';
699
+
700
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
701
+
702
+ type Intersection = UnionToIntersection<Union>;
703
+ //=> {the(): void; great(arg: string): void; escape: boolean};
704
+ ```
705
+
706
+ A more applicable example which could make its way into your library code follows.
707
+
708
+ @example
709
+ ```
710
+ import type {UnionToIntersection} from 'type-fest';
711
+
712
+ class CommandOne {
713
+ commands: {
714
+ a1: () => undefined,
715
+ b1: () => undefined,
716
+ }
717
+ }
718
+
719
+ class CommandTwo {
720
+ commands: {
721
+ a2: (argA: string) => undefined,
722
+ b2: (argB: string) => undefined,
723
+ }
724
+ }
725
+
726
+ const union = [new CommandOne(), new CommandTwo()].map(instance => instance.commands);
727
+ type Union = typeof union;
728
+ //=> {a1(): void; b1(): void} | {a2(argA: string): void; b2(argB: string): void}
729
+
730
+ type Intersection = UnionToIntersection<Union>;
731
+ //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
732
+ ```
733
+
734
+ @category Type
735
+ */
736
+ type UnionToIntersection<Union> = (
737
+ // `extends unknown` is always going to be the case and is used to convert the
738
+ // `Union` into a [distributive conditional
739
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
740
+ Union extends unknown
741
+ // The union type is used as the only argument to a function since the union
742
+ // of function arguments is an intersection.
743
+ ? (distributedUnion: Union) => void
744
+ // This won't happen.
745
+ : never
746
+ // Infer the `Intersection` type since TypeScript represents the positional
747
+ // arguments of unions of functions as an intersection of the union.
748
+ ) extends ((mergedIntersection: infer Intersection) => void)
749
+ // The `& Union` is to allow indexing by the resulting type
750
+ ? Intersection & Union
751
+ : never;
752
+
753
+ /**
754
+ Create a union of all keys from a given type, even those exclusive to specific union members.
755
+
756
+ Unlike the native `keyof` keyword, which returns keys present in **all** union members, this type returns keys from **any** member.
757
+
758
+ @link https://stackoverflow.com/a/49402091
759
+
760
+ @example
761
+ ```
762
+ import type {KeysOfUnion} from 'type-fest';
763
+
764
+ type A = {
765
+ common: string;
766
+ a: number;
767
+ };
768
+
769
+ type B = {
770
+ common: string;
771
+ b: string;
772
+ };
773
+
774
+ type C = {
775
+ common: string;
776
+ c: boolean;
777
+ };
778
+
779
+ type Union = A | B | C;
780
+
781
+ type CommonKeys = keyof Union;
782
+ //=> 'common'
783
+
784
+ type AllKeys = KeysOfUnion<Union>;
785
+ //=> 'common' | 'a' | 'b' | 'c'
786
+ ```
787
+
788
+ @category Object
789
+ */
790
+ type KeysOfUnion<ObjectType> =
791
+ // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
792
+ keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
793
+
794
+ /**
795
+ Extract all optional keys from the given type.
796
+
797
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
798
+
799
+ @example
800
+ ```
801
+ import type {OptionalKeysOf, Except} from 'type-fest';
802
+
803
+ interface User {
804
+ name: string;
805
+ surname: string;
806
+
807
+ luckyNumber?: number;
808
+ }
809
+
810
+ const REMOVE_FIELD = Symbol('remove field symbol');
811
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
812
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
813
+ };
814
+
815
+ const update1: UpdateOperation<User> = {
816
+ name: 'Alice'
817
+ };
818
+
819
+ const update2: UpdateOperation<User> = {
820
+ name: 'Bob',
821
+ luckyNumber: REMOVE_FIELD
822
+ };
823
+ ```
824
+
825
+ @category Utilities
826
+ */
827
+ type OptionalKeysOf<BaseType extends object> = KeysOfUnion<{
828
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
829
+ }>;
830
+
691
831
  /**
692
832
  Extract all required keys from the given type.
693
833
 
@@ -712,11 +852,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
712
852
 
713
853
  @category Utilities
714
854
  */
715
- type RequiredKeysOf<BaseType extends object> = Exclude<{
716
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
717
- ? Key
718
- : never
719
- }[keyof BaseType], undefined>;
855
+ type RequiredKeysOf<BaseType extends object> =
856
+ BaseType extends unknown // For distributing `BaseType`
857
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
858
+ : never; // Should never happen
720
859
 
721
860
  /**
722
861
  Returns a boolean for whether the given type is `never`.
@@ -1092,45 +1231,6 @@ type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
1092
1231
  IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
1093
1232
  );
1094
1233
 
1095
- /**
1096
- Extract all optional keys from the given type.
1097
-
1098
- This is useful when you want to create a new type that contains different type values for the optional keys only.
1099
-
1100
- @example
1101
- ```
1102
- import type {OptionalKeysOf, Except} from 'type-fest';
1103
-
1104
- interface User {
1105
- name: string;
1106
- surname: string;
1107
-
1108
- luckyNumber?: number;
1109
- }
1110
-
1111
- const REMOVE_FIELD = Symbol('remove field symbol');
1112
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
1113
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
1114
- };
1115
-
1116
- const update1: UpdateOperation<User> = {
1117
- name: 'Alice'
1118
- };
1119
-
1120
- const update2: UpdateOperation<User> = {
1121
- name: 'Bob',
1122
- luckyNumber: REMOVE_FIELD
1123
- };
1124
- ```
1125
-
1126
- @category Utilities
1127
- */
1128
- type OptionalKeysOf<BaseType extends object> = Exclude<{
1129
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
1130
- ? never
1131
- : Key
1132
- }[keyof BaseType], undefined>;
1133
-
1134
1234
  /**
1135
1235
  Matches any primitive, `void`, `Date`, or `RegExp` value.
1136
1236
  */
@@ -1197,7 +1297,11 @@ type ApplyDefaultOptions<
1197
1297
  IfNever<SpecifiedOptions, Defaults,
1198
1298
  Simplify<Merge<Defaults, {
1199
1299
  [Key in keyof SpecifiedOptions
1200
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
1300
+ as Key extends OptionalKeysOf<Options>
1301
+ ? Extract<SpecifiedOptions[Key], undefined> extends never
1302
+ ? Key
1303
+ : never
1304
+ : Key
1201
1305
  ]: SpecifiedOptions[Key]
1202
1306
  }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
1203
1307
  >>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/shared",
3
- "version": "1.40.2-next.0",
3
+ "version": "1.40.2-next.1",
4
4
  "description": "ESLint React's Shared constants and functions.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -39,16 +39,16 @@
39
39
  "picomatch": "^4.0.2",
40
40
  "ts-pattern": "^5.7.0",
41
41
  "valibot": "^1.0.0",
42
- "@eslint-react/eff": "1.40.2-next.0",
43
- "@eslint-react/kit": "1.40.2-next.0"
42
+ "@eslint-react/eff": "1.40.2-next.1",
43
+ "@eslint-react/kit": "1.40.2-next.1"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@tsconfig/node22": "^22.0.1",
47
- "@types/picomatch": "^3.0.2",
47
+ "@types/picomatch": "^4.0.0",
48
48
  "fast-equals": "^5.2.2",
49
49
  "micro-memoize": "^4.1.3",
50
50
  "tsup": "^8.4.0",
51
- "type-fest": "^4.38.0",
51
+ "type-fest": "^4.39.0",
52
52
  "@local/configs": "0.0.0"
53
53
  },
54
54
  "engines": {