-
Notifications
You must be signed in to change notification settings - Fork 64
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
assoc typing issue #90
Comments
Following https://gist.github.com/donnut/fd56232da58d25ceecf1
interface CurriedFunction2<T1, T2, R> {
(t1: T1): (t2: T2) => R;
(t1: T1, t2: T2): R;
} seem not will work for all cases where params, but: interface CurriedFunction2<T1, T2, R> {
<T1, T2, R>(t1: T1, t2: T2): R;
<T1>(t1: T1): <T2, R>(t2: T2) => R;
} will work as allows to extract params from type chain: assoc<T, U, R>(prop: string): CurriedFunction2<T, U, R> For example such case: const map = (func: (some: string) => (x: number) => 1) => {
return func('xx')(1)
}
const map2 = (func: (some: string, other: string) => '1') => {
return func('xx', 'x')
}
// will work only with proposed changes
map(R.assoc('xxx'))
map2(R.assoc('xxx')) If adding params to interface CurriedFunction2WithoutTypeParam {
<T1, T2, R>(t1: T1, t2: T2): R;
<T1>(t1: T1): <T2, R>(t2: T2) => R;
} @donnut what do you think about this issue? |
Thanks. It seems most of the remaining issues concern currying/composition, and this suggestion might address a key part of that. I'll try to update the definitions based on this. |
I tried adding all of the outstanding issues as tests, and manually tried your suggested typings to see how it would affect the results. Update: I was trying to see how this might work for bits where the returned value is a curried function -- in those cases the generics could only be passed at the initial function. It seems that version also makes your tests pass, and would give me a way to generalize this concept to the other cases as well. Feedback welcome. |
Ok, thanks, will see how it will work out. |
By now, #73 pushed me in the opposite direction, showing that redefined generics are in fact bug rather than feature. I've now re-diagnosed your actual issue, and it does in fact seem to be the same problem about generics within curried functions as reported in #78, and I suppose the composition-related ones #86, #92, and #101. |
assoc<T,U>(prop: string, val: T, obj: U): {prop: T} & U;
{prop: T}
? Unfortunately TS is not ready not handle such case with dynamic typing yet.microsoft/TypeScript#1295
The text was updated successfully, but these errors were encountered: