From 9fb56c7e73cd4b7e81e2c8ee4ce5dab55a2f0147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20H=C3=BCbelbauer?= Date: Tue, 21 Feb 2023 07:59:01 +0100 Subject: [PATCH] fix: prettify intersected types when selecting multiple columns (#399) * Prettify intersected types when selecting multiple columns Resolves #398 * update type test --------- Co-authored-by: Bobbie Soedirgo --- src/select-query-parser.ts | 4 ++-- src/types.ts | 3 +++ test/index.test-d.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) 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