-
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
Apply TS 2.1 keyof
& mapped types
#119
Comments
Thanks! I've now tried to use these in Now lenses are a bit tough. Since you brought them up, I tried to expand on typings there, but I'm not sure yet how I can use interface KeyLens<K extends keyof T> {
<T extends Struct<any>>(obj: T): T[K]; // get
<T extends Struct<any>>set(v: T[K], obj: T): T;
// <T extends Struct<any>>map(fn: (v: T[K]) => T[K], obj: T): T
} The main issue here is of course, such a lens is actually generic, in the sense it's agnostic toward the actual data structure it might be applied to. We'd like to be able to define such a lens just by the key it navigates to, but if we wish to apply Alternatively, we can add this T in the interface generics already, before There might be a way to improve on that, but I'm not sure if it could work in the current state of TS. |
@tycho01 |
Whoa, that's awesome, thank you! 😄 It evidently did better than my threads on |
Hello :) I'm clearly struggling understanding this new syntax... Example:
This get's me:
What should I use as the second parameter of EDIT: nevermind, the problem is not on my code, but here. A bug? |
Hey, this appears to be the regression described in #129. I haven't had the time to test their fix though... if the new nightly works we can just update it. |
TS 2.1 now supports
keyof
operator and mapped typeshttps://github.com/Microsoft/TypeScript/wiki/What's-new-in-TypeScript#keyof-and-lookup-types
It would be useful to type different methods like
prop
,lens
, etcThe text was updated successfully, but these errors were encountered: