From 9dd41d9c17a5d1b82144451d3eaf5729f2921758 Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Thu, 28 Mar 2024 18:15:12 +0800 Subject: [PATCH] feat: typecheck table names in `.from()` (#528) --- src/PostgrestClient.ts | 1 - test/basic.ts | 2 ++ test/index.test-d.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PostgrestClient.ts b/src/PostgrestClient.ts index d6f99f90..c30981d0 100644 --- a/src/PostgrestClient.ts +++ b/src/PostgrestClient.ts @@ -63,7 +63,6 @@ export default class PostgrestClient< from( relation: ViewName ): PostgrestQueryBuilder - from(relation: string): PostgrestQueryBuilder /** * Perform a query on a table or a view. * diff --git a/test/basic.ts b/test/basic.ts index 9a170019..3191f969 100644 --- a/test/basic.ts +++ b/test/basic.ts @@ -629,6 +629,7 @@ test('throwOnError throws errors instead of returning them', async () => { let isErrorCaught = false try { + // @ts-expect-error: nonexistent table await postgrest.from('missing_table').select().throwOnError() } catch (error) { expect(error).toMatchInlineSnapshot( @@ -642,6 +643,7 @@ test('throwOnError throws errors instead of returning them', async () => { test('throwOnError throws errors which include stack', async () => { try { + // @ts-expect-error: nonexistent table await postgrest.from('does_not_exist').select().throwOnError() } catch (err) { expect(err instanceof Error).toBe(true) diff --git a/test/index.test-d.ts b/test/index.test-d.ts index 54ee54f3..066892d2 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -10,6 +10,7 @@ const postgrest = new PostgrestClient(REST_URL) // table invalid type { expectError(postgrest.from(42)) + expectError(postgrest.from('nonexistent_table')) } // `null` can't be used with `.eq()`