title: Why shouldn't we write validation checks in different if statements in Typescript?
body: <p><a href="https://www.typescriptlang.org/docs/handbook/2/narrowing.html" rel="nofollow noreferrer">https://www.typescriptlang.org/docs/handbook/2/narrowing.html</a></p>
  <pre><code>function printAll(strs: string | string[] | null) {
    // !!!!!!!!!!!!!!!!
    //  DON'T DO THIS!
    //   KEEP READING
    // !!!!!!!!!!!!!!!!
    if (strs) {
      if (typeof strs === &quot;object&quot;) {
        for (const s of strs) {
          console.log(s);
        }
      } else if (typeof strs === &quot;string&quot;) {
        console.log(strs);
      }
    }
  }
  </code></pre>
  <blockquote>
  <p>We wrapped the entire body of the function in a truthy check, but this
  has a subtle downside: we may no longer be handling the empty string
  case correctly.</p>
  <p>TypeScript doesn’t hurt us here at all, but this is behavior worth
  noting if you’re less familiar with JavaScript. TypeScript can often
  help you catch bugs early on, but if you choose to do nothing with a
  value, there’s only so much that it can do without being overly
  prescriptive. If you want, you can make sure you handle situations
  like these with a linter.</p>
  </blockquote>
  <p>It seems to be more readable. Why is Typescript saying that we shouldn't check for the null states in different if statements?</p>
  <p>I didn't understand their explanations.
  Please explain.</p>