title: Typescript error Object is possibly null? Why, how to disable?
body: <p>I have the following code:</p>
  
  <pre><code>private extractInitials(fullname: string): string {
      const initials = fullname
          .replace(/[^a-zA-Z- ]/g, '')
          .match(/\b\w/g)
          .join('')
          .toUpperCase();
      return initials.substring(0, 2);
  }
  </code></pre>
  
  <p>I'm getting an error
  <a href="https://i.stack.imgur.com/NQXgY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NQXgY.png" alt="enter image description here"></a></p>
  
  <p><code>[ts] Object is possibly 'null'. [2531]</code></p>
  
  <p>So I tried 
  <code>if fullname { const initials .... return ... } else return '';</code></p>
  
  <p>Turns out typescript was complaining about this guy</p>
  
  <p><code>fullname.replace(/[^a-zA-Z- ]/g, '')</code></p>
  
  <p>Which makes sense because this might end up being an empty string</p>
  
  <p>So I did </p>
  
  <pre><code>const t = fullname.replace(/[^a-zA-Z- ]/g, '')
  if(t) { /* do the rest */ } else return ''
  </code></pre>
  
  <p>and it still gave me the object is possibly null error. I know it's not. How do I fix?</p>