Always use proper null safety patterns when accessing properties that might be null or undefined. This prevents runtime errors and improves code robustness.
Key practices:
// ✅ Consistent optional chaining configResult.config?.selectedModelByRole?.chat?.completionOptions
2. Verify object type before accessing properties, especially with DOM elements:
```typescript
// ❌ Unsafe - activeElement could be null
document.activeElement.classList.contains("ProseMirror")
// ✅ Type-safe access
if (document.activeElement instanceof Element &&
document.activeElement.classList.contains("ProseMirror"))
// ✅ Safe with fallback startIndex = nodeTextValue?.indexOf(query, startIndex) ?? -1;
4. Prefer positive conditions for null checks:
```typescript
// ❌ Less readable
onTitleClick={!item.content ? undefined : handleTitleClick}
// ✅ More readable
onTitleClick={item.content ? handleTitleClick : undefined}
Enter the URL of a public GitHub repository