title: Typescript conditional type - implement a type changing function
body: <p>I have objects with properties. These properties can either be single valued, or list valued and some properties are optional, means, they could be undefined. So here are some example objects:</p>
  
  <pre><code>type A = {
     myProp: string;
     otherProp?: number;
  }
  
  type B = {
     coolProp?: boolean[];
     someProp: SomeOtherType[];
  }
  </code></pre>
  
  <p>edit:
  <s>Now, I implemented a function, that takes such an object and the name of a property and returns that property as it was, for one exception: If the property is NOT optional AND NOT an array, it returns that property as an array with the original type as an array type.</s></p>
  
  <p>Now, I implemented a function, that takes such an object and the name of a property and returns that property as it was, for one exception: If the property is NOT an array, it returns that property as an array with the original type as an array type.</p>
  
  <p><s>So for example, properties from type B from above would not change, but <code>myProp: string;</code> from type A would become: <code>myProp: string[];</code>. <code>otherProp?: number</code> would also stay the same.</s></p>
  
  <p>So for example, properties from type B from above would not change, but <code>myProp: string;</code> from type A would become: <code>myProp: string[];</code>. <code>otherProp?: number</code> would become <code>otherProp?: number[]</code>.</p>
  
  <p>Now I want to put this behaviour into a return type definition in an interface, but I cannot for the life of me figure out, how to make it work.</p>
  
  <p>My best attempt was:</p>
  
  <pre><code>getPropFromObject&lt;O, P extends keyof O&gt;(node: O, propName: P):
      any[] extends O[P] ? O[P] : O[P] extends undefined ? O[P] : O[P][]
  </code></pre>
  
  <p>but it fails for single optional props like <code>otherProp?: number;</code></p>
  
  <p>How would a correct type definition look like?</p>