-
-
Notifications
You must be signed in to change notification settings - Fork 673
Add built-in indexof/valueof types #671
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
Conversation
Nice. What about type ValueOf<T> = T[keyof T]; |
That's what I meant with a bit short-sighted. A proper implementation would first need a new type node kind |
I see. So as intermediate solution this definitely make sense |
Count me in! This enables many great comparison patterns for my testing software. |
Thinking about this a little more, I figured that having our own special types might actually better represent what these actually do, because in TS, type TheType = keyof Array<i32>; // number | "length" | "fill" ... which is most likely nothing we'd support anytime soon anyway. Now, sadly, |
It would be awesome to have a type declaration statement in the function body. type Child = indexof<T>; // etc. Just my 2 cents. At first glance, I think this might cause problems with the resolver. I would be grateful for the type itself without the statement :) . |
This now adds indexed access overloads for Map and Set to unify/simplify the concept by binding it to |
This PR investigates a special type
valueof<T>
that obtains the value type of an array, a set, a map or a class with an indexed get overload (like typed arrays).Might help to implement things like #516 but the implementation is actually a bit short-sighted. TypeScript supports resolving types of the form
T[0]
for example, that does exactly this, but the resolver isn't yet powerful enough to support this (resolving of any expression etc.). So I guess the question is: Does it make sense to add this now, and once the resolver has been reworked, simply keep supporting it for backwards compatibility?