Skip to content

Commit

Permalink
fix(types): avoid never when column is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Sep 8, 2022
1 parent de12b67 commit 279b0c0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/database/type.ts
Expand Up @@ -22,16 +22,20 @@ export abstract class Type<
}

/** Convert a Postgres type to a JavaScript type */
export type Value<T> = T extends Type<any, infer V> ? V : T
export type Value<T> = T extends any
? T extends Type<any, infer V>
? V
: T
: never

/** Convert a Postgres object to a JavaScript object */
/** Convert a Postgres row to a JavaScript object */
export type Values<T extends object> = Intersect<
keyof T extends infer Column
? Column extends keyof T
? T[Column] extends Type<any, infer Value>
? undefined extends Value
? { [P in Column]?: Value }
: { [P in Column]: Value }
? Value<T[Column]> extends infer ColumnValue
? undefined extends ColumnValue
? { [P in Column]?: ColumnValue }
: { [P in Column]: ColumnValue }
: never
: never
: never
Expand Down

0 comments on commit 279b0c0

Please sign in to comment.