Generated type for `JSONB NOT NULL` column allows `null`

Open
#1,055 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
postgresql, typescript
Domain
databases

Research direction

Start by tracing the supabase gen types --lang=typescript entry point and how a non-nullable JSONB column is represented in the generated output. Confirm the generated type for that column no longer allows null, matching the database constraint and the expected NonNullable<Json> behavior.

Written by the indexing model from the issue text.

Description

bug

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

When I create a JSONB column that is explicitly NOT NULL, I can see that null values are not allowed according to Supabase Studio (it understands the Postgres restriction exists).

image

When I generate Typescript types for this database, however, the Json type for this column allows null.

image image

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a non-nullable JSONB column
  2. Run supabase gen types --lang=typescript
  3. View the generated type for the column, which is Json

Expected behavior

I would expect the Typescript type for this column to be NonNullable<Json>.

Screenshots

(See above)

System information

  • OS: macOS
  • supabase: ^1.200.3
  • Node: v20
Dominant language
TypeScript
Stars
1.2k
Forks
223
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/postgres-meta

All issues in supabase/postgres-meta

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.