How can I cast response.body to the type of options.responseType argument? TypeScript playground
The code block bellow is a simplified version of my code... many more options exist.
import got from "got"
interface Options {
responseType?: "buffer" | "json"
}
const get = async (url: string, options?: Options) => {
let response = await got.get(url, {
responseType: options?.responseType ?? "json"
})
return response.body
}