-
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
path
methods typing
#269
Comments
I was just about to link to the thread at TS, then realized you were the OP there. :) |
But if I'm not mistaken it works well for basic cases [string, string, string], the only problem is just with the size of signature needed, no? As I said just add common case for 3-4 length string tupple. |
We do not support the 1-length tuple version since it's a special case that tuples with any length can be all considered 1-length tuple, it's the super type of any tuple. @tycho01, It seems we did not support R.path(['a', 'c'], { a: { c: 1 } }); //=> number
R.path(['a', 'c'], { a: { c: 1 }, b: 2 }); //=> {} |
Uhh. afaik there are no special cases, it sees length 2 tuples as super types of length 3+ tuples too. That could be addressed by just putting higher length options first I guess.
Hm... if it messed up on that I imagine it could be addressed by ensuring we'd match using objects containing a string index as well, e.g. |
The declare function path2<T1 extends string, T2 extends string, TResult>(path: [T1, T2], obj: {
[K1 in T1]: {
[K2 in T2]: TResult;
};
}): TResult;
declare function path2withAny<T1 extends string, T2 extends string, TResult>(path: [T1, T2], obj: {
[K1 in T1]: {
[K2 in T2]: TResult;
} & {
[X: string]: any;
};
} & {
[X: string]: any;
}): TResult;
path2(["a", "b"], { a: { b: 1 }}); //=> 1
path2(["a", "b"], { a: { b: 1 }, c: 2 });
/* ^^^^^^^^^^^^^^^^^^^^^
[ts]
Argument of type '{ a: { b: number; }; c: number; }' is not assignable to parameter of type '{ a: { b: ((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?...'.
Types of property 'a' are incompatible.
Type '{ b: number; }' is not assignable to type '{ b: ((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?: Num...'.
Types of property 'b' are incompatible.
Type 'number' is not assignable to type '((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?: NumberFo...'.
*/
path2withAny(["a", "b"], { a: { b: 1 }}); //=> 1
path2withAny(["a", "b"], { a: { b: 1 }, c: 2 });
/* ^^^^^^^^^^^^^^^^^^^^^
[ts]
Argument of type '{ a: { b: number; }; c: number; }' is not assignable to parameter of type '{ a: { b: ((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?...'.
Type '{ a: { b: number; }; c: number; }' is not assignable to type '{ a: { b: ((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?...'.
Types of property 'a' are incompatible.
Type '{ b: number; }' is not assignable to type '{ b: ((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?: Num...'.
Type '{ b: number; }' is not assignable to type '{ b: ((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?: Num...'.
Types of property 'b' are incompatible.
Type 'number' is not assignable to type '((radix?: number) => string) | (() => number) | ((locales?: string | string[], options?: NumberFo...'.
*/ |
For posterity,
This is fixed since microsoft/TypeScript#17765. So, I haven't paid attention to Flow in a while, notably because the timing I entered front-end engineering got me on the Angular / TS path. But honestly, that looks great. What I'm getting from this example, and a subsequent glimpse at their docs:
These are the exact game-changers essential for FP I've been clamoring for in TS for ages, and I suppose it only makes sense FB's team behind React and Immutable.js would ensure to get them in. I guess this goes to show competition is great. I'd seriously consider retrying Flow if I were to try front-end again. Being able to use FP abstractions without having to fight the type system just might make it enjoyable again. :) |
@goodmind: curious to figure out how Flow would fare, I tried a bit to see if I could port my type lib to it in a new branch, WIP. Thoughts:
Guess I'm still pretty new to it, so not quite sure where to look or who to ask yet. @ikatyang your Jest testing method wasn't taken from a Flow equivalent either, right? |
I'm not sure what do you mean the testing method, but I didn't use Flow before so it shouldn't be. |
Also I think you can't just convert directly all this things |
replying at KiaraGrouwstra/typical#12 to keep this on-topic. thanks for the input ika. |
There probably a solution for 2.8 worth looking microsoft/TypeScript#12290 (comment) |
So what about
path
(assocPath, etc) methods typings?Maybe type them for most common cases like
string
props, and up to 3-4 path length?The text was updated successfully, but these errors were encountered: