10LOC

#parsing

TypeScriptintermediate

unknown plus a type guard instead of any for safe parsing

type ApiUser = { id: string; email: string };

const isApiUser = (value: unknown): value is ApiUser =>
  typeof value === "object" &&
  value !== null &&

Accept untyped input like JSON.parse's output without any, by narrowing it through a type predicate before touching its fields.