fix(types): resolve GetItemKeys / GetItemValue with branded and complex types#6073
Open
fix(types): resolve GetItemKeys / GetItemValue with branded and complex types#6073
Conversation
…ex types Add a non-recursive `_FlatItem<I>` helper as a fast-path for `GetItemKeys` and `GetItemValue`. TypeScript defers evaluation of the recursive `NestedItem<T>` when item types contain branded or complex intersections, making `GetItemKeys` opaque and preventing concrete string keys from being assignable. `_FlatItem` performs a simple 2-level array unwrap that TypeScript can always eagerly evaluate. `NestedItem` and `DotPathKeys` are kept as fallbacks so deeply nested arrays continue to work. Fixes nuxt#6072
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #6072
GetItemKeys<I>andGetItemValuerely onNestedItem<T>, a recursive conditional type. When item types contain branded types, complex intersections, or readonly symbol properties, TypeScript defers evaluation ofNestedItem<T>— the resulting type becomes opaque and concrete string keys like"id"or"name"are no longer assignable toGetItemKeys<I>. This also breaksv-modelinference throughGetModelValue.Changes
Added a non-recursive
_FlatItem<I>helper that performs a simple 2-level array unwrap. Since it's non-recursive, TypeScript can always eagerly resolve it.GetItemKeys: addedkeyof Extract<_FlatItem<I>, object>as the first union member (fast-path).NestedItemandDotPathKeysare kept as fallbacks so deeply nested arrays continue to work.GetItemValue: changed the default type parameter fromNestedItem<I>to_FlatItem<I>, and added akeyof Tfast-path before theDotPathKeysbranch.Why a new type instead of fixing
NestedItem?NestedItemis recursive by design — it handles arbitrarily nested arrays (T[][][]...). TypeScript's deferred evaluation of recursive conditional types is expected behavior and cannot be avoided._FlatItemprovides an eagerly-resolvable alternative for the common case (1-2 levels of array nesting) while keepingNestedItemfor the general case.Testing
Verified that:
T & { readonly [symbol]: B }) now work withvalue-key,label-key, andv-modelonUSelect,USelectMenu, andUInputMenuT[][]) still resolve correctly through theNestedItemfallback