Back to all reviewers

Validate object availability

block/goose
Based on 2 comments
TSX

Always verify that objects and their properties exist before accessing them to prevent null reference errors. This includes checking for undefined global objects, optional parameters, and nested properties.

Null Handling TSX

Reviewer Prompt

Always verify that objects and their properties exist before accessing them to prevent null reference errors. This includes checking for undefined global objects, optional parameters, and nested properties.

When you know an object or property is guaranteed to exist (like when checking param.default exists), keep the logic simple and avoid unnecessary validation:

// Good: Simple check when we know default exists
if (param.requirement === 'optional' && param.default) {
  initialValues[param.key] = param.default;
}

When accessing potentially undefined objects, add explicit checks:

// Good: Check object existence before use
useEffect(() => {
  if (window.electron) {
    const currentVersion = window.electron.getVersion();
    setUpdateInfo((prev) => ({ ...prev, currentVersion }));
  }
}, []);

This prevents runtime errors and makes your code more robust by handling null/undefined cases explicitly rather than assuming objects will always be available.

2
Comments Analyzed
TSX
Primary Language
Null Handling
Category

Source Discussions