Here is a unique question that delves into the nuances of type manipulation in TypeScript. Rather than focusing on obtaining return values of generic functions, this query explores transforming a specific type Have
into another type Want<T>
.
Imagine having an object with properties that are all functions, some of which are generic functions with a single parameter. For example:
type Have = {
foo: <T>(dep: {dependency: (a:T, b:T) => T}) => (a:T) => T
bar: <T>() => (a: T) => string
}
The goal here is to create a new generic type, Want<T>
, where each property corresponds to the type of the function in the original object but instantiated at the given parameter. In this case, the desired outcome would be:
type Want<T> = {
foo: (dep: {dependency: (a:T, b:T) => T}) => (a:T) => T
bar: () => (a: T) => string
}
So, the question remains: Is there a way to transform the type Have
into Want<T>
? This could involve purely type-level manipulation or potentially utilizing an object of type Have
as well.