fix: add | null to composite type fields in TypeScript generator#1063
Open
nancysangani wants to merge 3 commits intosupabase:masterfrom
Open
fix: add | null to composite type fields in TypeScript generator#1063nancysangani wants to merge 3 commits intosupabase:masterfrom
nancysangani wants to merge 3 commits intosupabase:masterfrom
Conversation
There was a problem hiding this comment.
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
| nullto 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Composite type fields were not emitting
| nullin 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 tounknownwithout| null.Before:
After:
Additional context
Per the PostgreSQL docs, composite type fields cannot have NOT NULL constraints, so every field is inherently nullable.