title: How to specify an interface with conditional properties in typescript?
body: <p>I'm creating a helper function to create new HTML elements</p>
  <pre><code>interface NewElement {
    type: string;
    className: string;
    innerText: string;
    href: string;
  }
  const createElement = ({ type, className, innerText, href }: NewElement) =&gt; {
    const element = document.createElement(type);
    innerText ? (element.innerText = innerText) : null;
    href ? (element.href = href) : null;
    className ? (element.className = className) : null;
    return element;
  };
  </code></pre>
  <p>If I want to create a <code>&lt;li&gt;</code> tag I don't need to pass the <code>href</code> for example</p>
  <pre><code>const li = createElement({ type: &quot;li&quot;, className: &quot;category&quot; });
  </code></pre>
  <p>The warning, rightly states <code>...Type '{ type: string; className: string; }' is missing the following properties from type 'NewElement': innerText, href</code></p>
  <p>Is there a way to do this?</p>