Let's consider the functions setup
and retrieve
:
function setup<Data = any>() {
// ...
}
function retrieve<Data = any>(): Data {
return 1 as Data
}
If we execute the setup
function:
type Item = {name: 'example'}
setup<Item>()
I am interested in automatically inferring the return type of the retrieve
function to be the same as the input type for the setup
function.
const result = retrieve()
// Desired outcome: the type of result is inferred as `Item`
I have a feeling this might not be achievable. One possible solution could involve having the setup
function return something of type S, which can then be passed to the retrieve
function. Are there any other approaches to tackle this issue?