Double return with a condition in Typescript
<p>Well, I'm trying to do something that I think is completely unnatural.</p>

<p>What I need to do, is to return different values depending on a <code>if</code>, like that :</p>

<pre><code>if(add)
    return {exists: myExists, key: myKey};

return myExists;
</code></pre>

<p>But then I got : <code>error TS2339: Property 'exists' does not exist on type '{ exists: boolean; key: number; } | boolean'.</code> at the compilation when I call the result of the function elsewhere.</p>

<p>Here is where I get the error (The return statement is in <code>IsInDays(value, add)</code>:</p>

<pre><code>AddDay(value){
    var datas = this.IsInDays(value, true);
    if(!datas.exists)
        this.days.push(value);
    else{
        this.days.splice(datas.key, 1);
    }

    console.log(this.days);
}
</code></pre>

<p>I do that because I don't know how to get the <code>exists</code> value for my <code>[ngClass]</code> statement (which calls the function) when it's in an object :/</p>

<p>If anybody knows a different way that would be awesome.</p>