You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am not sure if this is a bug or a design limitation, but when you have a function with narrowed overloads (see example) you cannot call the function with a broader union type although the union type does not go out of bounds of the overloads.
🔎 Search Terms
union types overloads
🕗 Version & Regression Information
I was unable to test this on prior versions because of time restraints
functionisOneOrTwo(it: unknown): it is (1|2){returnit===1||it===2;}functiondoSomething(it: unknown){if(isOneOrTwo(it)){returndoSomethingElse(it);}else{thrownewError("out of range");}}functiondoSomethingElse(it: 1): "one";functiondoSomethingElse(it: 2): "two";functiondoSomethingElse(it: number){switch(it){case1:
return"one";case2:
return"two";default:
thrownewError("out of range");}}
🙁 Actual behavior
The compiler reports an error on the call to doSomethingElse because the union type is not assignable to either of the overloads.
🙂 Expected behavior
The function is callable and returns a union type of the relevant overload's return values.
The text was updated successfully, but these errors were encountered:
Bug Report
I am not sure if this is a bug or a design limitation, but when you have a function with narrowed overloads (see example) you cannot call the function with a broader union type although the union type does not go out of bounds of the overloads.
🔎 Search Terms
union types overloads
🕗 Version & Regression Information
⏯ Playground Link
Simplified example
💻 Code
🙁 Actual behavior
The compiler reports an error on the call to
doSomethingElse
because the union type is not assignable to either of the overloads.🙂 Expected behavior
The function is callable and returns a union type of the relevant overload's return values.
The text was updated successfully, but these errors were encountered: