Exhaustive Switch in TypeScript

Hello, I am currently writing a little backend code with TypeScript, and I want to use some exhaustive switch to give back my client proper errors.
However, the types are not work as what I expected, can someone help me?

TS Playground: https://tsplay.dev/w29YrW
I don't understand why both result1 on line 25 and result2 on line 42 are of type ErrorResult but behaves differently when I switch on them.
How can I handle the errors properly?
Should I manually type the secondService so that it returns ErrorResult<"not permitted" | "not found"> ?
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Was this page helpful?