How to catch undefined after conditional?

Viewed 57

Consider following example:

function myFunc (b: number): string {
  let a: { c: any }

  if (b < 20) a = { c: 100 }

  console.log(a.c) // depending on 'b' this may throw error
  return 'ok'
}

I want my linter to tell me about this particular problem - that variable may be undefined. What rules should I use? I tried: no-undef, no-undef-init, no-undefined and no-use-before-define

0 Answers
Related