Skip to content

Commit 9dd41d9

Browse files
authored
feat: typecheck table names in .from() (#528)
1 parent e26266a commit 9dd41d9

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

src/PostgrestClient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ export default class PostgrestClient<
6363
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
6464
relation: ViewName
6565
): PostgrestQueryBuilder<Schema, View, ViewName>
66-
from(relation: string): PostgrestQueryBuilder<Schema, any, any>
6766
/**
6867
* Perform a query on a table or a view.
6968
*

test/basic.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ test('throwOnError throws errors instead of returning them', async () => {
629629
let isErrorCaught = false
630630

631631
try {
632+
// @ts-expect-error: nonexistent table
632633
await postgrest.from('missing_table').select().throwOnError()
633634
} catch (error) {
634635
expect(error).toMatchInlineSnapshot(
@@ -642,6 +643,7 @@ test('throwOnError throws errors instead of returning them', async () => {
642643

643644
test('throwOnError throws errors which include stack', async () => {
644645
try {
646+
// @ts-expect-error: nonexistent table
645647
await postgrest.from('does_not_exist').select().throwOnError()
646648
} catch (err) {
647649
expect(err instanceof Error).toBe(true)

test/index.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
1010
// table invalid type
1111
{
1212
expectError(postgrest.from(42))
13+
expectError(postgrest.from('nonexistent_table'))
1314
}
1415

1516
// `null` can't be used with `.eq()`

0 commit comments

Comments
 (0)