<p dir="auto">It would be great if there was a way to relax the current constraint of requiring get/set accessors to have the same type. this would be helpful in a situation like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="class MyClass {

    private _myDate: moment.Moment;

    get myDate(): moment.Moment {
        return this._myDate;
    }

    set myDate(value: Date | moment.Moment) {
        this._myDate = moment(value);
    }
}"><pre class="notranslate"><code class="notranslate">class MyClass {

    private _myDate: moment.Moment;

    get myDate(): moment.Moment {
        return this._myDate;
    }

    set myDate(value: Date | moment.Moment) {
        this._myDate = moment(value);
    }
}
</code></pre></div>
<p dir="auto">Currently, this does not seems to be possible, and I have to resort to something like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="class MyClass {

    private _myDate: moment.Moment;

    get myDate(): moment.Moment {
        return this._myDate;
    }

    set myDate(value: moment.Moment) {
        assert.fail('Setter for myDate is not available. Please use: setMyDate() instead');
    }

    setMyDate(value: Date | moment.Moment) {
        this._myDate = moment(value);
    }
}"><pre class="notranslate"><code class="notranslate">class MyClass {

    private _myDate: moment.Moment;

    get myDate(): moment.Moment {
        return this._myDate;
    }

    set myDate(value: moment.Moment) {
        assert.fail('Setter for myDate is not available. Please use: setMyDate() instead');
    }

    setMyDate(value: Date | moment.Moment) {
        this._myDate = moment(value);
    }
}
</code></pre></div>
<p dir="auto">This is far from ideal, and the code would be much cleaner if different types would be allowed.</p>
<p dir="auto">Thanks!</p>
<p dir="auto"><strong>Expected behavior</strong></p>
<p dir="auto">This function should compile succesfully</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="function testFunction(a: string | Object) {
  if (typeof a === &quot;string&quot;) {
    if (a.indexOf(&quot;.&quot;) &gt;= 0)
      a = a.substr(a.indexOf(&quot;.&quot;) + 1);
    ...
  }
}"><pre class="notranslate"><code class="notranslate">function testFunction(a: string | Object) {
  if (typeof a === "string") {
    if (a.indexOf(".") &gt;= 0)
      a = a.substr(a.indexOf(".") + 1);
    ...
  }
}
</code></pre></div>
<p dir="auto"><strong>Actual behavior</strong></p>
<p dir="auto">The function gives error about <code class="notranslate">indexOf</code> does not exist on type <code class="notranslate">string | Object</code>. If I omit the assignment to <code class="notranslate">a</code> then it works fine. I think the compiler should notice that I'm safely assigning another <code class="notranslate">string</code> to the <code class="notranslate">string</code> type-guarded variable. However, I understand that this behavior would be expected if I assigned a value which is not guaranteed to be a <code class="notranslate">string</code>.</p>
<p dir="auto"><strong>TypeScript environment</strong></p>
<p dir="auto">Visual Studio 2015<br>
TypeScript 1.8.4</p>