Back to all reviewers

explicit null handling

prisma/prisma
Based on 8 comments
TypeScript

Prefer explicit null and undefined handling over optional or nullable types. When possible, provide default values or objects instead of making parameters optional. When null/undefined checks are necessary, handle both values explicitly and use descriptive patterns.

Null Handling TypeScript

Reviewer Prompt

Prefer explicit null and undefined handling over optional or nullable types. When possible, provide default values or objects instead of making parameters optional. When null/undefined checks are necessary, handle both values explicitly and use descriptive patterns.

Instead of relying on optional parameters that create chains of conditional access:

// Avoid
interface MigrateSetupInput {
  schemaFilter?: MigrateTypes.SchemaFilter
}
// Later: schemaFilter?.['prop'] access

// Prefer
const defaultSchemaFilter = {
  externalTables: [],
  exclude: [],
} satisfies MigrateTypes.SchemaFilter

When checking for null/undefined values, be explicit about both:

// Handle both null and undefined
if (obj.currentTimeframe == null) {
  return {}
}

// Or check explicitly
if (response.body === null) {
  return reject(new Error('response.body is null'))
}

This approach reduces conditional access chains, makes code more predictable, prevents null reference errors, and improves type safety by making the presence or absence of values explicit rather than implicit.

8
Comments Analyzed
TypeScript
Primary Language
Null Handling
Category

Source Discussions