diff --git a/src/select-query-parser.ts b/src/select-query-parser.ts index dc90ec78..5f8c5a74 100644 --- a/src/select-query-parser.ts +++ b/src/select-query-parser.ts @@ -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' @@ -342,7 +342,7 @@ type GetResultHelper< ? GetResultHelper & Acc> : Fields extends [infer R, ...infer Rest] ? GetResultHelper & Acc> - : Acc + : Prettify /** * Constructs a type definition for an object based on a given PostgREST query. diff --git a/src/types.ts b/src/types.ts index f9bbf662..480e8260 100644 --- a/src/types.ts +++ b/src/types.ts @@ -69,3 +69,6 @@ export type GenericSchema = { Views: Record Functions: Record } + +// https://twitter.com/mattpocockuk/status/1622730173446557697 +export type Prettify = { [K in keyof T]: T[K] } & {} diff --git a/test/index.test-d.ts b/test/index.test-d.ts index cec1a1ae..b6d388d0 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -52,7 +52,7 @@ const postgrest = new PostgrestClient(REST_URL) if (error) { throw new Error(error.message) } - expectType<{ bar: Json } & { baz: string }>(data) + expectType<{ bar: Json, baz: string }>(data) } // rpc return type