Skip to content

Commit fbeb24c

Browse files
wyozisoedirgo
authored andcommitted
enforce non-null parameter to .eq
1 parent be421d9 commit fbeb24c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/PostgrestFilterBuilder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ export default class PostgrestFilterBuilder<
3131
Result,
3232
Relationships = unknown
3333
> extends PostgrestTransformBuilder<Schema, Row, Result, Relationships> {
34-
eq<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this
35-
eq(column: string, value: unknown): this
34+
eq<ColumnName extends string & keyof Row>(
35+
column: ColumnName,
36+
value: NonNullable<Row[ColumnName]>
37+
): this
38+
eq<Value extends unknown>(column: string, value: NonNullable<Value>): this
3639
/**
3740
* Match only rows where `column` is equal to `value`.
3841
*

test/index.test-d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
1111
expectError(postgrest.from(42))
1212
}
1313

14+
// test filters
15+
{
16+
postgrest.from('users').select().eq('username', 'foo')
17+
expectError(postgrest.from('users').select().eq('username', null))
18+
19+
const nullableVar = 'foo' as string | null
20+
expectError(postgrest.from('users').select().eq('username', nullableVar))
21+
}
22+
1423
// can override result type
1524
{
1625
const { data, error } = await postgrest

0 commit comments

Comments
 (0)