Skip to content

Commit

Permalink
enforce non-null parameter to .eq
Browse files Browse the repository at this point in the history
  • Loading branch information
wyozi authored and soedirgo committed Aug 24, 2023
1 parent be421d9 commit fbeb24c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/PostgrestFilterBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ export default class PostgrestFilterBuilder<
Result,
Relationships = unknown
> extends PostgrestTransformBuilder<Schema, Row, Result, Relationships> {
eq<ColumnName extends string & keyof Row>(column: ColumnName, value: Row[ColumnName]): this
eq(column: string, value: unknown): this
eq<ColumnName extends string & keyof Row>(
column: ColumnName,
value: NonNullable<Row[ColumnName]>
): this
eq<Value extends unknown>(column: string, value: NonNullable<Value>): this
/**
* Match only rows where `column` is equal to `value`.
*
Expand Down
9 changes: 9 additions & 0 deletions test/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ const postgrest = new PostgrestClient<Database>(REST_URL)
expectError(postgrest.from(42))
}

// test filters
{
postgrest.from('users').select().eq('username', 'foo')
expectError(postgrest.from('users').select().eq('username', null))

const nullableVar = 'foo' as string | null
expectError(postgrest.from('users').select().eq('username', nullableVar))
}

// can override result type
{
const { data, error } = await postgrest
Expand Down

0 comments on commit fbeb24c

Please sign in to comment.