title: Using tagged unions from JavaScript with wasm-bindgen
body: <p>I have a JavaScript object type where the <code>kind</code> field determines what other fields are present. Examples:</p>
  <pre class="lang-js prettyprint-override"><code>{ kind: 0, name: &quot;foo&quot; }
  { kind: 1, name: &quot;foo&quot;, value: 69 }
  { kind: 2 }
  </code></pre>
  <p>I put it into an <code>extern</code> block to use it in Rust:</p>
  <pre class="lang-rust prettyprint-override"><code>#[wasm_bindgen]
  extern &quot;C&quot; {
      type Foo;
  }
  </code></pre>
  <p>I need to access a <code>Foo</code> value's fields in this function:</p>
  <pre class="lang-rust prettyprint-override"><code>#[wasm_bindgen]
  fn use_foo(foo: Foo) {
      // ...
  }
  </code></pre>
  <p>How do I do this in a type-safe way?</p>