Optional properties can be missing. Sometimes a field is present but set to null. Treat both as "no value." When a string is present, you can clean it up.
const raw: string | null | undefined = " [email protected] ";
const cleaned = raw?.trim().toLowerCase();Return a new object when you make changes so callers keep their old data if needed.
Make a new user object with a normalized email field.
interface User { name: string; email?: string | null }.normalizeEmail(u: User): User.email is a string, set it to email.trim().toLowerCase(); if the trimmed value is '', treat it as missing.email is null or undefined, leave it missing.