Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardTypeScriptcontrol-flow analysis pitfallsSingle-choice MCQ

For element-access narrowing like `obj[k]`, what does TypeScript require of the key `k` to keep the narrowing across statements?

function f(obj: Record<string, string | undefined>, k: string) { if (obj[k] !== undefined) { obj[k].toUpperCase(); // ok here } k = "x"; // <-- adding this changes the result above }