We tell it that the value returned from a function is of type Array. As you can notice above I've removed any comma or wrapping into Array in function in favor of defining type later on and it seems to work just the way I want it to. Alternatively, you could always go for returning an object with a comma only if it's a single element. This way you get both of worlds.