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
typescript throws error when you want to initialize an arrow function that returns different objects based on overloaded string literal union typeΒ #55606
// normal function overload works well!functiontest(v:"hello"):{hello:number};functiontest(v:"hi"):{hi:boolean};functiontest(v: string){if(v==="hello"){return{hello:123};}elsereturn{hi:true}}// returnType is correct!;test("hello");// throws error in arrow function!typeoverload={(v:"hello"):{hello:number};(v:"hi"):{hi:boolean};}consttest2:overload=(v)=>{if(v==="hello"){return{hello:123};}elsereturn{hi:true}}// returnType is correct!;test2("hello");
π Actual behavior
typescript throws error when you want to initialize an arrow function that returns different objects based on overloaded string literal union type.
π Expected behavior
TS most not throws error in this case as it does not throws error in normal function