I've missed a basic type of TypeScript: Tuples.
So the semantics of UnionA and UnionB are different:
let x: UnionA = 0 // works
let x: UnionA = "" // works
let x: UnionB = 0 // doesn't work
let x: UnionB = "" // doesn't work
let x: UnionB = [0] // works
let x: UnionB = [""] // works
Basically UnionB is a tuple of length 1 with its first element being a union of number | string.
In retrospect, the linked question most likely
- didn't mean to use [] to get the plain union type, or
- was intended to use , instead of | to get a meaningful tuple with multiple fields.