title: Dart JS Interop Function overloading for typing
body: <p>I have defined a D3 Dart JS Interop, that I am using to set values on D3 objects and call them, which is working well. Unfortunately D3 uses the same function for both setters and getters, and depends on the amount of arguments to set them apart.</p>
  
  <p>For example, the Arc object has the ability to set and get an InnerRadius like this (in JavaScript):</p>
  
  <pre><code>var arc = d3.arc().innerRadius(25);
  //arc with innerRadius of 25
  var radius = arc.innerRadius();
  //radius is 25
  </code></pre>
  
  <p>The Dart wrapper I've defined looks like this:</p>
  
  <pre><code>@JS('d3')
  library d3;
  
  import 'dart:js';
  import "package:js/js.dart";
  
  @JS("arc")
  class Arc {
    external Arc innerRadius(num innerRadius);
    external Arc();
  }
  </code></pre>
  
  <p>And I would like to define a wrapper like this:</p>
  
  <pre><code>@JS("arc")
  class Arc {
    external Arc innerRadius(num innerRadius);
    external num innerRadius();
    external Arc();
  }
  </code></pre>
  
  <p>But it complains about the name already being defined. How do I define the dart wrapper so that I can both set and recall the value while also typing it?</p>
  
  <p>D3 defines an Arc like this:</p>
  
  <pre><code>function arcInnerRadius(d) {
      return d.innerRadius;
  }
  
  function constant$1(x) {
      return function constant() {
          return x;
      }
  }
  
  function arc() {
      var innerRadius = arcInnerRadius;
  
      function arc() {
          var r0 = +innerRadius.apply(this, arguments);
          //calculate and return path
      }
  
      arc.innerRadius = function(_) {
          if(arguments.length) {
              if(_ === "function") {
                  innerRadius = _;
              } else {
                  innerRadius = constant$1(+_);
              }
              return arc;
          }
          return innerRadius;
      }
  
      return arc;
  }
  </code></pre>
  
  <p>Thus the getter and setter syntax doesn't wrap it properly. As setting innerRadius sets the function which is not called by the code, not the internal value which is.</p>
  
  <p>There is an ugly solution, wherein if you drop the typing and make the parameter optional it allows you to do both. So my current solution is to define the wrapper like this:</p>
  
  <pre><code>@JS('d3')
  library d3;
  
  import 'dart:js';
  import "package:js/js.dart";
  
  
  @JS("arc")
  class Arc {
      external Arc();
      external innerRadius([num innerRadius]);
  }
  </code></pre>
  
  <p>Which allows you to call it like this:</p>
  
  <pre><code>Arc arc = new Arc()
      ..innerRadius(25);
  num radius = arc.innerRadius();
  </code></pre>
  
  <p>This works but has the downside in that we lose some of the value of typing in that I can't type force the radius to be a number. That is, this is equally valid:</p>
  
  <pre><code>Point&lt;num&gt; radius = arc.innerRadius();
  </code></pre>
  
  <p>And it won't explode until run-time.</p>
  
  <p>So this matches the function it is mapping and it works, but what I'm really after is the ability to do it with types and thus define a function with the same name that can both return the same type.</p>