-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
bug: type predicates (V is T
) fails on expressions (V[K] is T
)
#12549
Comments
The type predicate syntax has always taken a parameter name on the left side of the |
Oh, yeah, |
Well it's only the parameter that a type predicate can operate on - in other words, you write function foo(x: any): x is string {
// ....
} As opposed to the following: function foo(x: any): any is string {
// ....
} |
I'm sorry, that would be my misinterpretation then. propIs<T, V, K extends keyof V, R extends V[K]>(type: T, name: K, obj: V): obj[name] is T; Still not okay though. I suppose it'd help if I had the ability to save this result to a new variable first, but I'm not confident I can do this in the type language... |
You could do something like this: propIs<T, V, K extends keyof V, R extends V[K]>(type: T, name: K, obj: V): obj is (V & Record<K, T>) |
Whoa, some out of the box thinking there, wouldn't have come up with that myself. Thanks for thinking along. :) |
TypeScript Version: nightly (2.2.0-dev.20161128)
Code
Expected behavior:
TS being totally cool with
V[K] is T
.Actual behavior:
Nope, many syntax errors.
The text was updated successfully, but these errors were encountered: