Typescript gen : invalid SQL Function types
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- postgresql, typescript
Research direction
Run supabase gen types typescript --local with the SQL function and domain reproduction, then trace the TypeScript generation entry point responsible for function Args and Returns. Compare the generated output with the expected nullable primitive and underlying domain types; done means the generated interface matches the expected example.
Written by the indexing model from the issue text.
Description
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
For both input and input types, typescript generation of SQL functions is invalid in some cases :
- Primitive types are generated as non-nullable (
typeinstead oftype | null) even though the function may accept NULL as input or output - Domain types are generated as
unknown
I think that this bug is not caused by a PostgreSQL limitation as views produce the correct typing : primitives are nullable, domains generate as their underlying type and when domains are marked NOT NULL they are even non-nullable in typescript.
To Reproduce
CREATE DOMAIN strict_text AS text NOT NULL;
CREATE FUNCTION some_function(arg strict_text)
RETURNS table (nulltext text, stricttext strict_text)
LANGUAGE SQL AS $$
SELECT NULL::uuid, arg
$$;
Generated type with supabase gen types typescript --local
export interface Database {
public: {
Functions: {
some_function: {
Args: {
arg: unknown
}
Returns: {
nulltext: string
stricttext: unknown
}[]
}
}
}
}
Expected behavior
Generated types should be
export interface Database {
public: {
Functions: {
some_function: {
Args: {
arg: string
}
Returns: {
nulltext: string | null
stricttext: string
}[]
}
}
}
}
System information
- OS: [e.g. Linux NixOS]
- Version of supabase CLI: 1.50.8
- Version of Node.js: 18.15.0
Additional context
I ❤️ the work being done and the mindset at Supabase. I believe strict typing is crucial to the success of a "backend in the DB" and I could help with a PR if I'm being given some pointers to the code responsible of the TS generation 👋
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 223
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from supabase/postgres-meta
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
supabase/postgres-meta#1147 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
supabase/postgres-meta#1146 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
supabase/postgres-meta#1142 ·
All issues in supabase/postgres-meta
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·