Skip to content

Commit

Permalink
fix(types): resolve ColumnRef in AliasMapping correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Sep 13, 2022
1 parent 372923f commit 898ffcb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/postgres/selection.ts
Expand Up @@ -55,10 +55,18 @@ type ResolveAliasMapping<T> = T extends AliasMapping
? { [P in keyof T]: ResolveAliasedValue<T[P]> }
: never

type ResolveAliasedValue<T> =
| (T extends CallExpression<infer ReturnType> ? ReturnType : never)
| ResolveColumnRefs<T>
type ResolveAliasedValue<T> = T extends CallExpression<infer ReturnType>
? ReturnType
: T extends ColumnRef<infer ColumnValue>
? ColumnValue
: never

/**
* Convert a union of column refs into an object type.
*
* This is used when a selector returns an array that
* includes at least one column ref.
*/
type ResolveColumnRefs<T> = unknown &
([Extract<T, ColumnRef>] extends [ColumnRef<any, infer Column>]
? Column extends string
Expand Down

0 comments on commit 898ffcb

Please sign in to comment.