Error TS2339 is TypeScript doing its job: you are reading a property it cannot prove exists. The right fix is almost never any — it is giving the compiler the type information it is missing.
The Error
Property 'name' does not exist on type '{}'. (ts2339)
Fix 1: Type Your API Responses
response.json() returns any/unknown. Tell TS what shape it is:
interface User { id: string; name: string; email: string; }
const res = await fetch("/api/user");
const user = (await res.json()) as User;
console.log(user.name); // ✅ known propertyFix 2: Narrow Union Types Before Access
type Shape =
| { kind: "circle"; radius: number }
| { kind: "square"; side: number };
function area(s: Shape) {
if (s.kind === "circle") return Math.PI * s.radius ** 2; // narrowed
return s.side ** 2;
}Fix 3: Index Signatures for Dynamic Keys
const config: Record<string, string> = {};
config["theme"] = "dark"; // ✅ any string key allowedFix 4: Augment a Third-Party Type
When a library is missing a property you need (e.g. a custom field on the Express Request), declare it once via module augmentation rather than casting everywhere.
Avoid the any Escape Hatch
Casting to any silences the error but throws away every guarantee TypeScript gives you. Prefer typing the source. If you must escape, use unknown and narrow.
