Skip to content

fix: add | null to composite type fields in TypeScript generator#1063

Open
nancysangani wants to merge 3 commits intosupabase:masterfrom
nancysangani:fix/composite-type-fields-nullable
Open

fix: add | null to composite type fields in TypeScript generator#1063
nancysangani wants to merge 3 commits intosupabase:masterfrom
nancysangani:fix/composite-type-fields-nullable

Conversation

@nancysangani
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Composite type fields were not emitting | null in the generated TypeScript types, making them incorrectly non-nullable.

Fixes #763

What is the new behavior?

All composite type fields now emit | null, including domain-typed fields which previously fell through to unknown without | null.

Before:

CompositeTypes: {
  t: {
    a: number
    b: unknown
  }
}

After:

CompositeTypes: {
  t: {
    a: number | null
    b: unknown | null
  }
}

Additional context

Per the PostgreSQL docs, composite type fields cannot have NOT NULL constraints, so every field is inherently nullable.

Copilot AI review requested due to automatic review settings April 13, 2026 12:38
@nancysangani nancysangani requested a review from a team as a code owner April 13, 2026 12:38
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes TypeScript type generation for PostgreSQL composite types by ensuring every composite type field is emitted as nullable (| null), including fields whose underlying type resolves to unknown (e.g., domain-typed fields).

Changes:

  • Updated the TypeScript template to always append | null to composite type attributes.
  • Extended the test database schema with a domain + composite type that uses it.
  • Updated TypeScript typegen snapshot expectations to include the new composite type and nullability.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/server/templates/typescript.ts Ensures composite type attributes are emitted as `${tsType}
test/db/00-init.sql Adds a domain and a composite type using that domain to exercise the domain-as-attribute case.
test/server/typegen.ts Updates expected generated TS output to include the new composite type and `

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Composite types can be null

2 participants