-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Defer indexed access type resolution #17521
Conversation
The immediate issue is resolved, however I don't think that's the complete fix. Currently, indexing errors are not properly reported: type E<T> = { true: 'true' }[ObjectHasKey<T, '1'>] // should error, `false` not handled
type ErrorExample = E<[string]> // any :/ Here's the complete set of tests I'm using: type StringContains<S extends string, L extends string> = (
{ [K in S]: 'true' } &
{ [key: string]: 'false'}
)[L]
type ObjectHasKey<O, L extends string> = StringContains<keyof O, L>
type A<T> = ObjectHasKey<T, '0'>
type B = ObjectHasKey<[string, number], '1'> // "true"
type C = ObjectHasKey<[string, number], '2'> // "false"
type D = A<[string]> // "true"
// should be an error, `false` not handled
type E<T> = { true: 'true' }[ObjectHasKey<T, '1'>]
type Juxtapose<T> = ({ true: 'otherwise' } & { [k: string]: 'true' })[ObjectHasKey<T, '1'>]
// "otherwise" is missing
type DeepError<T> = { true: 'true' }[Juxtapose<T>]
// should be OK
type DeepOK<T> = { true: 'true', otherwise: 'false' }[Juxtapose<T>] |
@gcnew With latest commits we can now properly reason about higher-order types of the form |
Thank you! I'm definitely aware we are on the edge here. I've been pondering whether it is more correct to leave the behaviour as is in master, or fix it. On the one hand, the All in all, I'm leaning towards the second option, the one implemented by this PR. It's unfortunate that |
Would this PR break trying to use property access to grab just |
@tycho01 As implemented in this PR, indexing will return just I was making an argument that the |
@gcnew: Yeah, I'll admit it's hard to foresee. Hopefully the test harness will help find out... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned in person that using TypeFlags.Index
requires a bit of implicit knowledge. Specifically, such types will only even exist when a lookup type can't operate eagerly. In other words, in keyof T
, T
must be a type variable to even have something with TypeFlags.Index
. An assertion about that somewhere would be helpful, but a long-term way of documenting that would potentially go farther.
Otherwise, the changes seem good to me. I don't see the above being a blocker.
@gcnew @tycho01 The changes related to transforming a mapped type |
With this PR we defer resolution of indexed access types in situations where we were previously too eager.
Fixes #17456.