Developing a type constructor for a function is my goal, where it takes a parameter S
and a function from S
to a different type, then applies that function on the input S
and produces the result:
// Previous approach which is limited to implementation details
function dig<S, R>(s: S, fn: (s: S) => R): R {
return fn(s);
}
// Alternative type constructor option focusing on specifying `R`
type Dig<S, R> = (s: S, fn: (s: S) => R) => R;
// Issue encountered due to missing available arguments
const d: Dig<string> = (s, fn) => fn(s);
Hence, I am exploring how to create a Dig<S>
type constructor that automatically deduces the return type of the provided fn
argument without the need for me to explicitly state the R
.