cf.completefrontend

ConceptHard

Why does TypeScript forget a narrowing inside a callback?

The code
type Profile = { name?: string }; function greetLater(profile: Profile) {  if (profile.name) {    setTimeout(() => {      console.log(profile.name.toUpperCase());    }, 100);  }}

The answer

Answer it out loud first, the way you would in the interview. Then compare.

Checking your sign-in…