Back to all reviewers

Check undefined before use

logseq/logseq
Based on 2 comments
TSX

Always verify that values are not undefined before accessing or using them, whether they are object properties or function parameters. This prevents TypeScript compilation errors and potential runtime issues.

Null Handling TSX

Reviewer Prompt

Always verify that values are not undefined before accessing or using them, whether they are object properties or function parameters. This prevents TypeScript compilation errors and potential runtime issues.

When accessing object properties that may not exist, use conditional checks or optional chaining. When dealing with function parameters that could be undefined, ensure proper type handling and validation.

Example from the codebase:

// Before: Direct property access (causes TS error)
<TablerIcon name="text" />

// After: Check existence before use
<TablerIcon name={shape.props.label || shape.props.text ? "forms" : "text"} />

// For function parameters, ensure types handle undefined:
// Instead of assuming 'color' exists, fix types in ColorInput to handle undefined values

This practice ensures type safety and prevents unexpected behavior when values might be missing or undefined.

2
Comments Analyzed
TSX
Primary Language
Null Handling
Category

Source Discussions