10000 Make function return types nullable by TomasHubelbauer · Pull Request #480 · supabase/postgres-meta · GitHub
[go: up one dir, main page]

Skip to content

Make function return types nullable #480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make function return types nullable
@psteinroe contributed a change which adds schema functions which take only the table name as columns on the tables when generating TypeScript types.

This commit extends that to treat function return types as nullable.

The function used in `oo-init.sql` could be changed like so:

```sql
create function public.blurb(public.todos) returns text as
$$
select null;
$$ language sql stable;
```

It would still compile and be a valid function despite the unchanged return type, which means any function must be treated as potentially returning `null` in the types.

I have also updated instructions for building and testing the TypeScript type generation.
  • Loading branch information
TomasHubelbauer authored and soedirgo committed Jan 28, 2023
commit 147e098a2a187460a664d143090d63360e7d881e
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ To start developing, run `npm run dev`. It will set up the database with Docker

If you are fixing a bug, you should create a new test case. To test your changes, add the `-u/--updateSnapshot` flag to `jest` on the `test:run` script, run `npm run test`, and then review the git diff of the snapshots. Depending on your change, you may see `id` fields being changed - this is expected and you are free to commit it, as long as it passes the CI. Don't forget to remove the `-u/--updateSnapshot` flag when committing.

To make changes to the TypeScript type generation, run `npm run gen:types:typescript` while you have `npm run dev` running.

## Licence

Apache 2.0
Expand Down
2 changes: 1 addition & 1 deletion src/server/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export interface Database {
fn.return_type,
types,
schemas
)}`
)} | null`
),
]}
}
Expand Down
0