Back to all reviewers

Explicit null handling

supabase/supabase
Based on 3 comments
TSX

Use explicit patterns when dealing with potentially null or undefined values to prevent runtime errors and improve code clarity: 1. **Mark optional properties with the `?` operator** in TypeScript interfaces when values might be undefined:

Null Handling TSX

Reviewer Prompt

Use explicit patterns when dealing with potentially null or undefined values to prevent runtime errors and improve code clarity:

  1. Mark optional properties with the ? operator in TypeScript interfaces when values might be undefined:
// Bad
interface GuideArticleProps {
  content: string
  mdxOptions: SerializeOptions
}

// Good
interface GuideArticleProps {
  content?: string
  mdxOptions?: SerializeOptions
}
  1. Prefer required properties when a value should always be present. This reduces defensive coding and makes contract expectations clear:
// Instead of allowing properties to be undefined and checking later
// Make them required in the interface/type definition
{
  status: edgeFunctionsStatus?.healthy,
  isSuccess: edgeFunctionsStatus?.healthy,
}
  1. Add explicit null checks before accessing properties of potentially undefined objects:
// Bad - may cause errors if currentOrg is undefined
enabled: !['team', 'enterprise'].includes(currentOrg?.plan.id ?? ''),

// Good - explicitly check existence first
enabled: currentOrg !== undefined && !['team', 'enterprise'].includes(currentOrg?.plan.id ?? ''),

Consistently applying these practices helps prevent null reference errors and makes code behavior more predictable across the codebase.

3
Comments Analyzed
TSX
Primary Language
Null Handling
Category

Source Discussions