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

Explain the unexpected type of `arr` after the loop. Why does CFA report `(string | number)[]` even though every push was a `number`?

function build(n: number) { let arr = []; // evolving any[] -> ? for (let i = 0; i < n; i++) arr.push(i); arr.push("done" as string); return arr; // inferred type? }