Better Typescript support for select()! #602
Unanswered
yankeeinlondon
asked this question in
Feature Requests
Replies: 2 comments 2 replies
-
Note: it would also be very helpful to expose your interfaces -- the implementation is unnecessary -- of elements like |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have two PRs open that would improve TS QoL: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using
io-ts
to provide strong type codec's for all tables in Postgres but in trying to provide better type support for the querying of tables I am running into issues with how types are exposed through@supabase/supabase-js
. As a "for instance", let's say I want to provide a type-aware "select" operation for a typescript type/interface called ISong. Let's also assume that this table is represented in Postgres as the "songs" table.Structurally, the operation would look like this in an untyped world:
Fortunately you provide the generic on the
from()
function where you should be able to construct a typed selected operation but the signature of select is inheritantly weakly typed and breaks the chain. Therefore, the following typed structure:Ideally the above would ensure that within select, only valid column names could be chosen but structurally you're asking for a single comma delimited string and this will never work. You do, however, forward the typing onward to the filter operation so do get strong typing on column name and column's value in the
eq(x,y)
operation:Making the select operation type-safe wouldn't be hard and I have worked around it with my wrapper by doing the following:
With this in place my wrapper allows me to simply define an
io-ts
type and then configure supabase like so:Everything in the chain -- including the table name -- is strongly typed. I got around the select's break but it would be nicer if there was a strongly typed way built in. I realize this probably forces a breaking change for your API but maybe there's a way to keep the old means while offering a type-safe option?
Beta Was this translation helpful? Give feedback.
All reactions