title: Function returning type used in a function taking a generic type parameter
body: <p>So I have this code:</p>
  
  <pre><code>type Zero = One = 1 | Two = 2 | Three = 3
  type Four = Five = 5 | Six = 6 | Seven = 7
  
  let test_1 (x : bool) : Type =
      if x
      then typeof&lt;Zero&gt;
      else typeof&lt;Four&gt;
  
  let test_2 () =
       let ty = test_1 true
       let e = enum&lt;ty&gt;(1)
       ...
  </code></pre>
  
  <p>However on the last line, I get an error: <code>Type ty not defined.</code></p>
  
  <p>Any suggestions?</p>
  
  <p>Edit:</p>
  
  <p>Or maybe something like this:</p>
  
  <pre><code>let test_3 (x : bool) (i : int) : obj =
      if x
      then enum&lt;Zero&gt;(i) :&gt; obj
      else enum&lt;Four&gt;(i) :&gt; obj
  </code></pre>
  
  <p>I was thinking would there be some way to regain type safety?</p>
  
  <p>Maybe something like this?</p>
  
  <pre><code>let test_4 (x : bool) (i : int) : obj * Type =
      if x
      then enum&lt;Zero&gt;(i) :&gt; obj, typeof&lt;Zero&gt;
      else enum&lt;Four&gt;(i) :&gt; obj, typeof&lt;Four&gt;
  </code></pre>
  
  <p>Then use it as so:</p>
  
  <pre><code>let test_5 () =
      let v,t = test_4 true 1
      let o = v :?&gt; t
      ...
  </code></pre>
  
  <p>This complains on the last line with t not defined.</p>
  
  <p>Basically what I'm trying to do is to be able to return these different enums without resorting to wrapping Zero and Four into a DU.</p>