Back to all reviewers

Use null strategically

supabase/supabase
Based on 2 comments
Typescript

When handling empty or missing values, be intentional about using `null`, `undefined`, or empty strings based on how downstream systems interpret these values. In particular, when working with database operations (like PostgreSQL), use `null` instead of empty strings for fields that need to be cleared or constraints that should be dropped.

Null Handling Typescript

Reviewer Prompt

When handling empty or missing values, be intentional about using null, undefined, or empty strings based on how downstream systems interpret these values. In particular, when working with database operations (like PostgreSQL), use null instead of empty strings for fields that need to be cleared or constraints that should be dropped.

// Bad: Using empty string or keeping values as-is
const comment = ((field.comment?.length ?? '') === 0 ? '' : field.comment)?.trim()
const check = field.check?.trim()

// Good: Converting empty values to null for database operations
const comment = field.comment?.trim() || null
const check = field.check?.trim() || null

This pattern ensures proper behavior when working with systems that treat null specially. For PostgreSQL specifically, NULL is required to remove comments or constraints, as empty strings are treated differently. Use the nullish coalescing operator (||) with null to handle this pattern concisely.

2
Comments Analyzed
Typescript
Primary Language
Null Handling
Category

Source Discussions