New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
My variable definitely isn't undefined. TypeScript disagrees.
What you'll have at the end
The same function with every possibly undefined error narrowed away instead of silenced
You need
A TypeScript project with strict null checks on, and a function somewhere in it that the checker has already flagged with a possibly undefined or possibly null error.
Not covered
Turning strict null checks off project-wide, or silencing the error with the non-null assertion operator: both hide the crash instead of preventing it.
Narrow an unknown JSON value before you trust it
For when the checker's complaint is that a value has no real shape at all, rather than a shape it already trusts but thinks might be absent.
Giving a fetch response a real type instead of any
For when a fetch response itself is typed as any and needs a shape in the first place, before absence ever becomes the question.
Checked 22 Aug 2026
Part of the TypeScript cookbook