When handling null/undefined, be explicit about intent:
undefined, ensure ?? falls back to the intended “truth” (not a stale previous value).ReactNode variants in a way that changes semantics between render modes (inline vs overflow). If separators/text are part of the host contract, preserve them intentionally.null: for union/enum switches, use an exhaustive pattern so new members don’t silently fall through to null.false (not undefined).Example (routing fallback):
const reportedWorkspaceCwd = connection.sessionId
? connection.workspaceCwd
: (selectedWorkspaceCwd ?? primaryWorkspaceCwd);
// If selectedWorkspaceCwd is undefined, fall back to primaryWorkspaceCwd—not a stale connection.workspaceCwd.
Example (exhaustive switch):
switch (checks) {
case 'passing': return ...;
case 'failing': return ...;
case 'none': return null;
default: {
const _exhaustive: never = checks;
return null;
}
}
Example (test nullability):
expect(latestChatEditorProps.disabled).toBe(false); // not undefined