https://www.typescriptlang.org/play?#code/FAEwpgxgNghgTmABAM...
However, if you check or assert that the returned value is one of the accepted literals, compiler accepts it:
This is one of the classic examples of flow-sensitive typing in TS.