From fbeb24c25e085d63720b82e7b9c9e1d93f13c8d4 Mon Sep 17 00:00:00 2001 From: Joonas Date: Tue, 22 Aug 2023 13:01:25 +0300 Subject: [PATCH] enforce non-null parameter to .eq --- src/PostgrestFilterBuilder.ts | 7 +++++-- test/index.test-d.ts | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/PostgrestFilterBuilder.ts b/src/PostgrestFilterBuilder.ts index 9f4c0807..e8da9a98 100644 --- a/src/PostgrestFilterBuilder.ts +++ b/src/PostgrestFilterBuilder.ts @@ -31,8 +31,11 @@ export default class PostgrestFilterBuilder< Result, Relationships = unknown > extends PostgrestTransformBuilder { - eq(column: ColumnName, value: Row[ColumnName]): this - eq(column: string, value: unknown): this + eq( + column: ColumnName, + value: NonNullable + ): this + eq(column: string, value: NonNullable): this /** * Match only rows where `column` is equal to `value`. * diff --git a/test/index.test-d.ts b/test/index.test-d.ts index d2407856..f88daec3 100644 --- a/test/index.test-d.ts +++ b/test/index.test-d.ts @@ -11,6 +11,15 @@ const postgrest = new PostgrestClient(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