How can I conditionally set return type based on params
As in playground, I'd like to return correct types described in comments based on
returnAxiosRequest
. Can you help out? I've tried overloading and conditional types, but failed. In terms of overloading, I would not like to overload getSomething
function as real case it's actually generated - Ideally TS magic should happen in request
function.
Nudge in the right direction would also be appreciated.
https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgMIHsQ2Ac2QbwF8BYAKDNElkRQHkAHMYTAZwLOWSgjAFcoQAQQAezFgCUILeqwgB+AFzIARunQAbCHBABuMiXKlK0eEmQixk6bIA8AFWQBeZNoCeAPnalOAEzhg4JTsAGg5kFgC+FiUQXgBbZWh9MjIYXhAEJkwuCABHXikwG3EnFxAPAAoETGwcJQwsXGDkdEZmEBZFZAYsjoBKL05qjrAc6w6IJQt0CSkZCeLPZ3xkPwClAG0AXRc2cWaI-15o5AAmAAZz5EI9Q05gGGQK1t7OgDpuPgFp2fGWCAG+DCnE+-BAY3m-1unAMYVBAghsjeazgyUMAHp0cgcDwAMroOI8AAWoBwbzALBSRnAJhoyHxhLAJJAeBWYRAcEJSgiUFJ0OQ1XSYBi8USUFusNIaQyvWxeIJxNJzzarC6PXaLEBcJ4YJy+UKNgZipZ7gqRGaLw1fTRZEx4QVAHcidAUBB1P8qcMIoiJgBGUo4sBGplKlbwoSiGZWSGTZBgKAFa59HTIO3cP4Qf0sInoXjqHwqFA-aO2YPMnDuW1YzjIAB6cjIXtG6ZjpwD8sZ5bNOS+Ecsc1kSng7pQhGTqaxLdkbezufzhfpCpDLKrNbrciAATS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
0 Replies