-
Notifications
You must be signed in to change notification settings - Fork 127
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
Add type safety for purry
#560
Comments
We don't really need a return type for purry because we instead rely on function overloads to define the purried overloaded type (which means For external usage, purry as a tool, I'd still recommend people implement helper functions the same way we do. So this brings me up to the question of whether a typed purry replaces the way we implement our functions substantially, removing the need to declare overloads to begin with and only typing the dataFirst impl and getting everything else inferred automatically. To answer that question, I think the main problem would be how do we handle generic functions, those that take a e.g. declare function map<T, S>(array: T[], mapper: (item: T) => S): S[];
function purriedMap(...args: PurriedParameters<typeof map>): PurriedReturnType<typeof map> {
return purry(map, args);
}
// Is x typed properly here?
const result = purriedMap([1,2,3], (x) => x + 1);
// what about here?
const result = pipe([1,2,3], purriedMap((x) => x + 1)); |
But |
I updated the code on the top. How about this? Maybe no overload is needed with this. |
I appreciate your intent, but it just doesn't work for generic functions (and can't as far as my experience with typescript goes). |
I think But it would be still useful to support type checking for overloading even if export type PurriedReturnType<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
F extends (...args: readonly any[]) => unknown,
> =
Parameters<F> extends readonly [infer T, ...unknown[]]
? ReturnType<F> | (value: T) => ReturnType<F>
: never; |
Hello. I published https://github.com/somnicattus/rotery/tree/master/src/compositions In this package I suggested type safe Can you see how worth it is?
|
How do you think about this?
Lazy is ignored because I don't know much about it.
concerns
It seems work well with non-generic function types, but not with generic function types... :(
implementations
usage
The text was updated successfully, but these errors were encountered: