Repository navigation
Key deferred indexed access types by their persistent access flags - #65450
Jake Bailey (jakebailey) wants to merge 2 commits into
Conversation
Reading obj[key] with a key of a union of type parameters gives a type that should be identical to T[K1 | K2] written in a type annotation. It is reported as not assignable to it, which TypeScript 6.0 accepts.
An indexed access type keeps only the persistent access flags, but the cache of deferred indexed access types was keyed by all of them, so an access made in an expression created a second type identical to the one written in a type annotation. Relating the two then could not use their identity, and simplified the source for reading and the target for writing, which are not related when the index is a union. TypeScript 6.0 keys the cache by the persistent access flags.
|
TypeScript Bot (@typescript-bot) test it |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the indexed-access cache-key fix and its regression coverage.
No open issues 🎉
What changed in this PR
Fixes a porting bug in the native TypeScript checker by using persistent access flags consistently when caching deferred indexed access types.
Changes:
- Aligns the cache key with the flags stored on the indexed access type.
- Adds regression cases for generic union-key accesses, with expected type and symbol baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/indexedAccessUnionKeyIdentity.ts |
Adds regression coverage for indexed access type identity. |
tsc/testdata/baselines/reference/compiler/indexedAccessUnionKeyIdentity.types |
Records expected types for the regression cases. |
tsc/testdata/baselines/reference/compiler/indexedAccessUnionKeyIdentity.symbols |
Records expected symbol bindings for the regression cases. |
tsc/internal/checker/checker.go |
Uses persistent access flags in the deferred indexed access cache key. |
Review effort: Balanced
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
See #65064 (comment)
This is just a porting bug
Strada (
src/compiler/checker.ts, ingetIndexedAccessTypeOrUndefined):Go on main (
tsc/internal/checker/checker.go:27786):The fix changes that one argument back to
persistentAccessFlags.