@@ -53,15 +53,16 @@ onlyAcceptNameImproved(invalidInput); // Compilation error
53
53
@category Utilities
54
54
*/
55
55
export type Exact < ParameterType , InputType > =
56
- // If the parameter is a primitive, return it as is immediately to avoid it being converted to a complex type
57
- ParameterType extends Primitive ? ParameterType
58
- // If the parameter is an unknown, return it as is immediately to avoid it being converted to a complex type
59
- : IsUnknown < ParameterType > extends true ? unknown
60
- // If the parameter is a Function, return it as is because this type is not capable of handling function, leave it to TypeScript
61
- : ParameterType extends Function ? ParameterType
62
- : IsEqual < ParameterType , InputType > extends true ? ParameterType
63
- // Convert union of array to array of union: A[] & B[] => (A & B)[]
64
- : ParameterType extends unknown [ ] ? Array < Exact < ArrayElement < ParameterType > , ArrayElement < InputType > > >
65
- // In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray.
66
- : ParameterType extends readonly unknown [ ] ? ReadonlyArray < Exact < ArrayElement < ParameterType > , ArrayElement < InputType > > >
67
- : ExactObject < ParameterType , InputType > ;
56
+ // Before distributing, check if the two types are equal and if so, return the parameter type immediately
57
+ IsEqual < ParameterType , InputType > extends true ? ParameterType
58
+ // If the parameter is a primitive, return it as is immediately to avoid it being converted to a complex type
59
+ : ParameterType extends Primitive ? ParameterType
60
+ // If the parameter is an unknown, return it as is immediately to avoid it being converted to a complex type
61
+ : IsUnknown < ParameterType > extends true ? unknown
62
+ // If the parameter is a Function, return it as is because this type is not capable of handling function, leave it to TypeScript
63
+ : ParameterType extends Function ? ParameterType
64
+ // Convert union of array to array of union: A[] & B[] => (A & B)[]
65
+ : ParameterType extends unknown [ ] ? Array < Exact < ArrayElement < ParameterType > , ArrayElement < InputType > > >
66
+ // In TypeScript, Array is a subtype of ReadonlyArray, so always test Array before ReadonlyArray.
67
+ : ParameterType extends readonly unknown [ ] ? ReadonlyArray < Exact < ArrayElement < ParameterType > , ArrayElement < InputType > > >
68
+ : ExactObject < ParameterType , InputType > ;
0 commit comments