Skip to content

Conversation

Shadowfiend
Copy link

When generating TypeScript types, the current code "correctly" reports numeric types as number, as Postgres and Postgrest return such columns as JSON numbers by default without a query ::text cast.

However, generated insert and update types are limited to number, whereas the underlying APIs will accept a string and allow preserving precision that would be lost in conversion to JS number this way.

Generated types for inserting and updating numeric fields now include | string as a possibility to allow for this.

Closes #972.

When generating TypeScript types, the current code "correctly" reports
numeric types as `number`, as Postgres and Postgrest return such columns
as JSON numbers by default without a query `::text` cast.

However, generated insert and update types are limited to `number`,
whereas the underlying APIs will accept a string and allow preserving
precision that would be lost in conversion to JS `number` this way.

Generated types for inserting and updating numeric fields now include
`| string` as a possibility to allow for this.
@Shadowfiend Shadowfiend requested review from a team as code owners August 8, 2025 16:43
Copy link
Member

@avallete avallete left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! I appreciate the effort you put into this PR.

That said, I’m not in favor of merging this as a global change. In most cases, this approach could introduce issues down the line, especially since it primarily affects bigint and similar fields. And could also constitute a breaking change in user code where functions might expect things to be a number and not a number | string type. Instead, I’d recommend handling this on a per-column basis like mentioned in the guide, if you know a specific column may have precision issues when converted in JavaScript, you can override it to be typed as number | string or number | bigint.

This way, we avoid broad changes that might cause unintended side effects while still giving flexibility where needed.

Comment on lines +147 to +149
if (column.name.toLowerCase().startsWith("decimal")) {
console.log("YOYOYOYO Insert", `'${column.name}'`, `'${column.format}'`)
}
Copy link
Member

Choose a reason for hiding this comment

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

issue

Probably don't want this to stay around.

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.

For numeric columns, TypeScript type generation does not include string as an option for inserts and updates
2 participants