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
constconfig={primaryFunctions: {'functionA': functionA,'functionB': functionB,},secondaryFunctions: {'functionC': functionC,}};functionfunctionA(str: string){returnstr+'A';}functionfunctionB(num: number){returncallSecondaryFunction('functionC',true)+'B';}functionfunctionC(bool: boolean){constx=!!callPrimaryFunction('functionA','test');// Comment this block and uncomment any of the others below:if(x){returnbool;}elsereturnfalse;//return x ? bool : false;// return x && bool}constcallPrimaryFunction=<Textendskeyoftypeofconfig.primaryFunctions>(functionName: T, ...args: Parameters<typeofconfig.primaryFunctions[T]>)=>{return(config.primaryFunctions[functionName]asany)(...args);}constcallSecondaryFunction=<Textendskeyoftypeofconfig.secondaryFunctions>(functionName: T, ...args: Parameters<typeofconfig.secondaryFunctions[T]>)=>{return(config.secondaryFunctions[functionName]asany)(...args);}console.log(callPrimaryFunction('functionA','test'));console.log(callPrimaryFunction('functionB',5));
🙁 Actual behavior
When you go to functionC comment the following block
if (x) {
return bool;
} else return false;
and uncomment any of the other two below:
//return x ? bool : false;
// return x && bool
you will get 'callPrimaryFunction' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.(7023) errors everywhere even though the code should work in an identical way.
🙂 Expected behavior
if (x) {
return bool;
} else return false;
or
return x ? bool : false;
or
return x && bool
should behave in the same way and not cause errors because they return the exact same result in Javascript.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered:
🔎 Search Terms
short circuit return error, ternary return error
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.4.5#code/MYewdgzgLgBKYDMCWBzGBeGBvAUDGADgE5IC2AhkQJ4BiArmMFEuBAFzZ74wDkCDTFmACCPDv0bNwwgDRd8fAVLAAhMTAmDwKufgC+umBACm8ACaVaSoe07dem5QGF1joU8N6cegNw4cbuAa1tIAFNBEHBFIYCgAlHYwRMZQdERgRlBEMADUvKJ+XgEhGYGqoWB0pByVpABGxkQJuPjJqelw5AA2XQDKpuAW1PSSQqGKo+AuMjBZdMYJeTxqhf5lwZNgTqF1ICBdHLv7xuRgzVzw0DAAHhgwAIT3wN1dAAokFMMl42WiMzxQYzQHhxPxcAD04JgThApFIxjAsCgAAskBAYHUuiBgABrGCnMwwASw+GI-FgKgwEAIWbI4xUlGNdENLEAdzYXCQNNC13O9jaaQyRy6fn0MGMXRMSRSgo03RMYPwkIFHVuAH4MXsujBxPLjKKYJDpe0MrcAGRmzX7bz+S6wZ49d5kSwjLQZTAAHgAKuLroCwGZ0TjjFRqbMqARjGH4MgUAA6YjOr6bCAAPlCZQAcuR4RwvTM44XKChbK9KDmUkyPVAI1GaTHUAmPi6ShAANpegC6qYS6FTiRVGVCDfjic+VhTbazFc7+PRpyocVChbjxYgoJtODtnR6-XMLc2d29vv9gZgwdDNJrkej4FjcZM++TbrTGZK2dzMHzMBXa44ZaICtASICBq1rW9EEbR9BgPF8O27Xt+xaY1ZWHO8oIGANYOUdtp3hWdyHnCkl1-IgSw3IpLmOOMsRQYcXidcdXWUH4Sj+XhAWBOINyorpjBokA6IdN5m2fFiJjdNQZgAVm4vwgA
💻 Code
🙁 Actual behavior
When you go to
functionC
comment the following blockand uncomment any of the other two below:
you will get
'callPrimaryFunction' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions.(7023)
errors everywhere even though the code should work in an identical way.🙂 Expected behavior
or
or
should behave in the same way and not cause errors because they return the exact same result in Javascript.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: