Narrowing down error type in catch : <p>For this piece of code</p>

<pre><code>try {
  throw new CustomError();
}
catch (err) {
  console.log(err.aPropThatDoesNotExistInCustomError);
}
</code></pre>

<p><code>err</code> is <code>any</code> and doesn't trigger type errors. How can it be narrowed down to the type that error is expected to be?</p>
