@eslint-react/shared 1.40.3 → 1.40.4-beta.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.
- package/dist/index.d.mts +6 -106
- package/dist/index.d.ts +6 -106
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -688,109 +688,6 @@ 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
691
|
/**
|
|
795
692
|
Extract all optional keys from the given type.
|
|
796
693
|
|
|
@@ -824,9 +721,12 @@ const update2: UpdateOperation<User> = {
|
|
|
824
721
|
|
|
825
722
|
@category Utilities
|
|
826
723
|
*/
|
|
827
|
-
type OptionalKeysOf<BaseType extends object> =
|
|
828
|
-
|
|
829
|
-
|
|
724
|
+
type OptionalKeysOf<BaseType extends object> =
|
|
725
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
726
|
+
? (keyof {
|
|
727
|
+
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
728
|
+
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
729
|
+
: never; // Should never happen
|
|
830
730
|
|
|
831
731
|
/**
|
|
832
732
|
Extract all required keys from the given type.
|
package/dist/index.d.ts
CHANGED
|
@@ -688,109 +688,6 @@ 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
691
|
/**
|
|
795
692
|
Extract all optional keys from the given type.
|
|
796
693
|
|
|
@@ -824,9 +721,12 @@ const update2: UpdateOperation<User> = {
|
|
|
824
721
|
|
|
825
722
|
@category Utilities
|
|
826
723
|
*/
|
|
827
|
-
type OptionalKeysOf<BaseType extends object> =
|
|
828
|
-
|
|
829
|
-
|
|
724
|
+
type OptionalKeysOf<BaseType extends object> =
|
|
725
|
+
BaseType extends unknown // For distributing `BaseType`
|
|
726
|
+
? (keyof {
|
|
727
|
+
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
728
|
+
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
729
|
+
: never; // Should never happen
|
|
830
730
|
|
|
831
731
|
/**
|
|
832
732
|
Extract all required keys from the given type.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/shared",
|
|
3
|
-
"version": "1.40.
|
|
3
|
+
"version": "1.40.4-beta.4",
|
|
4
4
|
"description": "ESLint React's Shared constants and functions.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,8 +39,8 @@
|
|
|
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.
|
|
43
|
-
"@eslint-react/kit": "1.40.
|
|
42
|
+
"@eslint-react/eff": "1.40.4-beta.4",
|
|
43
|
+
"@eslint-react/kit": "1.40.4-beta.4"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@tsconfig/node22": "^22.0.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"fast-equals": "^5.2.2",
|
|
49
49
|
"micro-memoize": "^4.1.3",
|
|
50
50
|
"tsup": "^8.4.0",
|
|
51
|
-
"type-fest": "^4.39.
|
|
51
|
+
"type-fest": "^4.39.1",
|
|
52
52
|
"@local/configs": "0.0.0"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|