Uh oh!
There was an error while loading. Please reload this page.
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: typeE<T>={true: 'true'}[ObjectHasKey<T,'1'>]// should error, `false` not handledtypeErrorExample=E<[string]>// any :/Here's the complete set of tests I'm using: typeStringContains<Sextendsstring,Lextendsstring>=({[KinS]: 'true'}&{[key: string]: 'false'})[L]typeObjectHasKey<O,Lextendsstring>=StringContains<keyofO,L>typeA<T>=ObjectHasKey<T,'0'>typeB=ObjectHasKey<[string,number],'1'>// "true"typeC=ObjectHasKey<[string,number],'2'>// "false"typeD=A<[string]>// "true"// should be an error, `false` not handledtypeE<T>={true: 'true'}[ObjectHasKey<T,'1'>]typeJuxtapose<T>=({true: 'otherwise'}&{[k: string]: 'true'})[ObjectHasKey<T,'1'>]// "otherwise" is missingtypeDeepError<T>={true: 'true'}[Juxtapose<T>]// should be OKtypeDeepOK<T>={true: 'true',otherwise: 'false'}[Juxtapose<T>] |
Anders Hejlsberg (ahejlsberg)
commented
Aug 2, 2017
Marin Marinov (@gcnew) With latest commits we can now properly reason about higher-order types of the form |
Marin Marinov (gcnew)
commented
Aug 2, 2017
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 |
kiara (KiaraGrouwstra)
commented
Aug 7, 2017
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 |
kiara (KiaraGrouwstra)
commented
Aug 7, 2017
Marin Marinov (@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.
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.
Anders Hejlsberg (ahejlsberg)
commented
Aug 7, 2017
Marin Marinov (@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.