Skip to content

Commit

Permalink
fix: prettify intersected types when selecting multiple columns (#399)
Browse files Browse the repository at this point in the history
* Prettify intersected types when selecting multiple columns

Resolves #398

* update type test

---------

Co-authored-by: Bobbie Soedirgo <[email protected]>
  • Loading branch information
TomasHubelbauer and soedirgo authored Feb 21, 2023
1 parent c3a8bf5 commit 9fb56c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/select-query-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Credits to @bnjmnt4n (https://www.npmjs.com/package/postgrest-query)

import { GenericSchema } from './types'
import { GenericSchema, Prettify } from './types'

type Whitespace = ' ' | '\n' | '\t'

Expand Down Expand Up @@ -342,7 +342,7 @@ type GetResultHelper<
? GetResultHelper<Schema, Row, [], ConstructFieldDefinition<Schema, Row, R> & Acc>
: Fields extends [infer R, ...infer Rest]
? GetResultHelper<Schema, Row, Rest, ConstructFieldDefinition<Schema, Row, R> & Acc>
: Acc
: Prettify<Acc>

/**
* Constructs a type definition for an object based on a given PostgREST query.
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ export type GenericSchema = {
Views: Record<string, GenericView>
Functions: Record<string, GenericFunction>
}

// https://twitter.com/mattpocockuk/status/1622730173446557697
export type Prettify<T> = { [K in keyof T]: T[K] } & {}
2 changes: 1 addition & 1 deletion test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
if (error) {
throw new Error(error.message)
}
expectType<{ bar: Json } & { baz: string }>(data)
expectType<{ bar: Json, baz: string }>(data)
}

// rpc return type
Expand Down

0 comments on commit 9fb56c7

Please sign in to comment.