Skip to content

feat: add fallback resolution for indexed access types#1831

Open
thazhemadam wants to merge 1 commit intolukeautry:masterfrom
thazhemadam:master
Open

feat: add fallback resolution for indexed access types#1831
thazhemadam wants to merge 1 commit intolukeautry:masterfrom
thazhemadam:master

Conversation

@thazhemadam
Copy link

@thazhemadam thazhemadam commented Feb 12, 2026

Indexed access patterns like T[keyof U], MappedType[Union], and (typeof x)[keyof typeof y] previously threw
"Unknown type: IndexedAccessType".

Add a fallback that delegates to TypeScript's type checker to evaluate any indexed access type the compiler accepts, then recursively resolves the resulting simpler type node.

All Submissions:

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Have you written unit tests?
  • Have you written unit tests that cover the negative cases (i.e.: if bad data is submitted, does the library respond properly)?
  • This PR is associated with an existing issue?

Closing issues

Closes #1622.

If this is a new feature submission:

  • Has the issue had a maintainer respond to the issue and clarify that the feature is something that aligns with the goals and philosophy of the project?

Potential Problems With The Approach

This doesn't fix all forms of the IndexedAccessTypeNode errors.
For instance, generic-dependent indexed access types (e.g., as in #1375) are not resolved by this change. In such cases, we bail out to avoid infinite recursion and throw the same error as before.

Test plan

Positive test cases:

  • ForeignIndexedValue: (typeof x)[keyof typeof y] where x and y are different objects. Asserts the schema resolves to { type: "string", enum: ["FOO"] }.
  • EventUnion: { [K in Union]: ... }[Union], a mapped type indexed by a union alias. Asserts the schema resolves to anyOf with 2 object variants, each containing the expected properties.
  • ConfigValue: ConfigMap[ConfigKey] where ConfigKey = keyof ConfigMap (GenerateMetadataError: Unknown type: IndexedAccessType #1622 pattern). Asserts the schema resolves to anyOf with 2 variants (the heterogeneous value types of the interface).

One negative test case that documents the known limitation:

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there thazhemadam 👋

Thank you and congrats 🎉 for opening your first PR on this project.✨

We will review the following PR soon! 👀

@thazhemadam thazhemadam force-pushed the master branch 2 times, most recently from 9ffc9e7 to b7dafdb Compare February 12, 2026 08:37
Indexed access patterns like `T[keyof U], MappedType[Union]`, and
`(typeof x)[keyof typeof y]` previously threw
"Unknown type: IndexedAccessType".

Add a fallback that delegates to TypeScript's type checker to evaluate
any indexed access type the compiler accepts, then recursively resolves
the resulting simpler type node.

In the fallback, ensure that we prevent infinite recursion when
`typeToTypeNode` returns another `IndexedAccessTypeNode`, e.g.
generic-dependent patterns like `DM[T]`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GenerateMetadataError: Unknown type: IndexedAccessType

1 participant