That's what enums/unions are for.
> It has become a point of doctrine among many programmers that the best way to prevent application bugs is strict type enforcement. But I find no evidence in support of this.
I find it hard to believe that static typechecking is not advantageous compared to checking for every returned value whether it's undefined or null or a string instead of the expected array. Flexible typing turns many compiler errors into runtime errors. Only one of those is guaranteed to be caught. There's a reason TypeScript got popular, and it's not the additional build step.