Skip to content

Commit e327521

Browse files
vonovaksoedirgo
authored andcommitted
feat: typecheck table names in from clause
1 parent 393423a commit e327521

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/SupabaseClient.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,12 @@ export default class SupabaseClient<
130130
}
131131

132132
// NOTE: signatures must be kept in sync with PostgrestClient.from
133-
from<
134-
TableName extends string & keyof Schema['Tables'],
135-
Table extends Schema['Tables'][TableName]
136-
>(relation: TableName): PostgrestQueryBuilder<Schema, Table, TableName>
137-
from<ViewName extends string & keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
133+
from<TableName extends keyof Schema['Tables'], Table extends Schema['Tables'][TableName]>(
134+
relation: TableName
135+
): PostgrestQueryBuilder<Schema, Table, TableName>
136+
from<ViewName extends keyof Schema['Views'], View extends Schema['Views'][ViewName]>(
138137
relation: ViewName
139138
): PostgrestQueryBuilder<Schema, View, ViewName>
140-
from(relation: string): PostgrestQueryBuilder<Schema, any, any>
141139
/**
142140
* Perform a query on a table or a view.
143141
*

test/index.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const supabase = createClient<Database>(URL, KEY)
99
// table invalid type
1010
{
1111
expectError(supabase.from(42))
12+
expectError(supabase.from('some_table_that_does_not_exist'))
1213
}
1314

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

0 commit comments

Comments
 (0)