Skip to content

Commit

Permalink
Only do a single level of expansion on parameters
Browse files Browse the repository at this point in the history
This gives us better-looking intersectioned objects, but avoids the
errors I saw with recursively-expanded types.
  • Loading branch information
markerikson committed Nov 17, 2021
1 parent 82d7b81 commit b7a7a6a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export type MergeParameters<
// 9) Tuples can have field names attached, and it seems to work better to remove those
RemoveNames<{
// 5) We know the longest params array has N args. Loop over the indices of that array.
[index in keyof LongestParamsArray]: LongestParamsArray[index] extends LongestParamsArray[number] // field names for array functions like `slice()` // 6) Do a check to ensure that we're _only_ checking numeric indices, not any
// 6) For each index, do a check to ensure that we're _only_ checking numeric indices,
// not any field names for array functions like `slice()`
[index in keyof LongestParamsArray]: LongestParamsArray[index] extends LongestParamsArray[number]
? // 8) Then, intersect all of the parameters for this arg together.
IntersectAll<
// 7) Since this is a _nested_ array, extract the right sub-array for this index
Expand Down Expand Up @@ -165,7 +167,7 @@ export type ExtractReturnType<T extends readonly UnknownFunction[]> = {

/** Recursively expand all fields in an object for easier reading */
export type ExpandItems<T extends readonly unknown[]> = {
[index in keyof T]: T[index] extends T[number] ? ComputeDeep<T[index]> : never
[index in keyof T]: T[index] extends T[number] ? Expand<T[index]> : never
}

/** First item in an array */
Expand Down

0 comments on commit b7a7a6a

Please sign in to comment.