Skip to content

Commit

Permalink
Merge pull request #162 from planetscale/type-cleanup
Browse files Browse the repository at this point in the history
Constructor type overloading cleanup
  • Loading branch information
ayrton authored Jan 30, 2024
2 parents 07a2329 + 26516a3 commit 7b49f94
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ type ExecuteAs = 'array' | 'object'

type ExecuteArgs = Record<string, any> | any[] | null

type ExecuteOptions<T extends ExecuteAs = 'object'> = T extends 'array'
? { as?: 'object'; cast?: Cast }
: T extends 'object'
? { as: 'array'; cast?: Cast }
: never

export class Client {
public readonly config: Config

Expand All @@ -121,12 +127,12 @@ export class Client {
async execute<T = Row<'object'>>(
query: string,
args?: ExecuteArgs,
options?: { as?: 'object'; cast?: Cast }
options?: ExecuteOptions<'object'>
): Promise<ExecutedQuery<T>>
async execute<T = Row<'array'>>(
query: string,
args: ExecuteArgs,
options: { as: 'array'; cast?: Cast }
options: ExecuteOptions<'array'>
): Promise<ExecutedQuery<T>>
async execute<T = Row<'object'> | Row<'array'>>(
query: string,
Expand All @@ -153,12 +159,12 @@ class Tx {
async execute<T = Row<'object'>>(
query: string,
args?: ExecuteArgs,
options?: { as?: 'object'; cast?: Cast }
options?: ExecuteOptions<'object'>
): Promise<ExecutedQuery<T>>
async execute<T = Row<'array'>>(
query: string,
args: ExecuteArgs,
options: { as: 'array'; cast?: Cast }
options: ExecuteOptions<'array'>
): Promise<ExecutedQuery<T>>
async execute<T = Row<'object'> | Row<'array'>>(
query: string,
Expand Down Expand Up @@ -224,12 +230,12 @@ export class Connection {
async execute<T = Row<'object'>>(
query: string,
args?: ExecuteArgs,
options?: { as?: 'object'; cast?: Cast }
options?: ExecuteOptions<'object'>
): Promise<ExecutedQuery<T>>
async execute<T = Row<'array'>>(
query: string,
args: ExecuteArgs,
options: { as: 'array'; cast?: Cast }
options: ExecuteOptions<'array'>
): Promise<ExecutedQuery<T>>
async execute<T = Row<'object'> | Row<'array'>>(
query: string,
Expand Down

0 comments on commit 7b49f94

Please sign in to comment.