Closed as not planned
Description
π Search Terms
arrow function
union
overload
π Version & Regression Information
all TS versions
β― Playground Link
π» Code
// normal function overload works well!
function test(v:"hello"):{hello:number};
function test(v:"hi"):{hi:boolean};
function test (v: string){
if(v === "hello"){
return {hello:123};
}else return {hi:true}
}
// returnType is correct!;
test("hello");
// throws error in arrow function!
type overload = {
(v:"hello"):{hello:number};
(v:"hi"):{hi:boolean};
}
const test2:overload = (v)=>{
if(v === "hello"){
return {hello:123};
}else return {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
Additional information about the issue
No response