Backend Sent null—Graceful Frontend Handling
2024-05-17
nickname: null is not the same as a missing key—or empty string. Mix them and you get UI bugs and bad PATCH payloads.
Three kinds of empty
Missing key; null literal; empty string ""—align with backend OpenAPI.
TypeScript
nickname?: string vs nickname: string | null mean different things.
Display
Normalize at API boundary; use placeholders for null in tables.
const label = user.nickname ?? "Not set";Forms
PATCH: omit = no change, null = clear—document and stick to it.