type-fest 3.5.2 → 3.5.3
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/package.json +1 -1
- package/source/exact.d.ts +10 -8
package/package.json
CHANGED
package/source/exact.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {KeysOfUnion, ArrayElement, ObjectValue} from './internal';
|
|
2
2
|
import type {Opaque} from './opaque';
|
|
3
|
+
import type {IsEqual} from './is-equal';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
Create a type from `ParameterType` and `InputType` and change keys exclusive to `InputType` to `never`.
|
|
@@ -50,11 +51,12 @@ onlyAcceptNameImproved(invalidInput); // Compilation error
|
|
|
50
51
|
@category Utilities
|
|
51
52
|
*/
|
|
52
53
|
export type Exact<ParameterType, InputType> =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: ParameterType extends
|
|
60
|
-
: ParameterType
|
|
54
|
+
IsEqual<ParameterType, InputType> extends true ? ParameterType
|
|
55
|
+
// Convert union of array to array of union: A[] & B[] => (A & B)[]
|
|
56
|
+
: ParameterType extends unknown[] ? Array<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
|
|
57
|
+
// In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray.
|
|
58
|
+
: ParameterType extends readonly unknown[] ? ReadonlyArray<Exact<ArrayElement<ParameterType>, ArrayElement<InputType>>>
|
|
59
|
+
// For Opaque types, internal details are hidden from public, so let's leave it as is.
|
|
60
|
+
: ParameterType extends Opaque<infer OpaqueType, infer OpaqueToken> ? ParameterType
|
|
61
|
+
: ParameterType extends object ? ExactObject<ParameterType, InputType>
|
|
62
|
+
: ParameterType;
|