-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Idea: Experiment / document generic lambda types further with HKTs. (e.g. <X>(x: X) => X
)
#78
Comments
I totally don't mind answering this. It seems you are making the assertion that a certain HKT cannot be constructed. The HKT you are interested in is an HKT which has the following behavior:
To my knowledge this is trivially accomplished via first defining |
This is indeed trivial as implemented here: https://tsplay.dev/wOXL7N Posting the actual block as well to avoid bit rot. import * as H from "hkt-toolbelt";
type _$promisify<T> = T extends (...args: infer Args) => infer R ? (...args: Args) => Promise<R> : never;
interface Promisify extends H.Kind.Kind { f(x: this[H.Kind._]): _$promisify<typeof x> } You should see that this representation works fine. You don't even need a separate This also works: import * as H from "hkt-toolbelt";
interface Promisify extends H.Kind.Kind {
f(x: this[H.Kind._]): typeof x extends (...args: infer Args) => infer R ? (...args: Args) => Promise<R> : never;
} I realize this doesn't implement the full complexity of your code above; indeed, the reason why your code doesn't work is because you are passing in a generic function type |
<X>(x: X) => X
)
<X>(x: X) => X
)<X>(x: X) => X
)
Hi,
This is not an issue, so feel free to close, but I had a question about mapping over a function's input and output at the type level, specifically for generic functions.
It seems that it is not possible to map over a function's input and output types while propagating type parameters, using this trick, and I was wondering if you had thought about this use case at all. For example, consider a HKT that takes a function and returns the same function except the output is wrapped in a Promise.
In this example the type parameters will be inferred as
unknown
. This is possible at the value level.Thanks for taking the time to entertain my question, this is a very interesting concept!
The text was updated successfully, but these errors were encountered: