title: Argument of type '(Node & ParentNode) | null' is not assignable to parameter of type 'Element'. Type 'null' is not assignable to type 'Element'
body: <p>I try to pass a <code>parentNode</code> of a node to my <code>getStyleComputedProperty</code> function.</p>
  <p>But got an error:</p>
  <blockquote>
  <p>Argument of type '(Node &amp; ParentNode) | null' is not assignable to parameter of type 'Element'.   Type 'null' is not assignable to type 'Element'.</p>
  </blockquote>
  <p>Code here:</p>
  <pre class="lang-js prettyprint-override"><code>type NonFunctionPropertyNames&lt;T&gt; = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];
  type Property = NonFunctionPropertyNames&lt;CSSStyleDeclaration&gt;;
  export const getStyleComputedProperty = (ele: Element, property: Property): string =&gt; {
    const css = window.getComputedStyle(ele, null);
    return css[property];
  };
  
  const div = document.createElement('div')
  getStyleComputedProperty(div.parentNode, 'position') // tsc throw error
  </code></pre>
  <p>I know I can use type cast like this <code>div.parentNode as Element</code> to pass the TSC type check. But I wonder how can I make the type correct without the type cast.</p>
  <p>Here is <a href="https://www.typescriptlang.org/play?#code/C4TwDgpgBAcg9gOwGIFcEGNgEtEAUBOck+oMAhgLYQDOAPACoB8UAvFAN5QDaA0lFgigBrCCDgAzKPQC6ALim9pUCAA9gEBABNqUasHwCA5lAD8UPvIQQAbhHxQAvlxFjJMgNwAoUJCgEidqCssIioGNh4hMSklDS0AMIAysmgADYQACIQ6Klk+GQRCIxeqmBwJFDoiHpQhhDAiWkQ8XAUYCjqmv7RIMEAFBDp8gCi6VQIwAA0UGBRgSDy3fMAlPJ6BgjGLMzsnlCV1cCV1DpsAO4CmnBnAHR1wC1tHRCajSDpA+nTCCipqctefb4eoofCCdAnLizAIkEDSLwOLyeKoIGqaLDWYJXdAocbAG7oYEFCCjCB4voAcnR1gpy089ze6Ue7U6S1hfWpNzAeQ0wHgmgg0wpZWoWEKtKAA" rel="nofollow noreferrer">TypeScript Playground</a></p>