Typescript function taking one or array of objects
<p>We are using simple function declaration quite a lot where function takes either single object or array of objects of some type. </p>

<p>Simple declaration is:</p>

<pre><code>interface ISomeInterface {
    name: string;
}

class SomeClass {
    public names: ISomeInterface[] = [];

    public addNames(names: ISomeInterface | ISomeInterface[]): void {
        names = (!Array.isArray(names)) ? [names] : names;
        this.names = this.names.concat(names);
    }    
}
</code></pre>

<p>But TypeScript throws "type is not assignable" error.</p>

<p>Is there better way of doing this? Obviously we could have two separate functions, but I think handling single vs multiple this way is quite fine.</p>