fix(types): preserve selector returnObjects shape with context (#2398)#2438
Merged
adrai merged 1 commit intoJun 26, 2026
Conversation
…xt#2398) Context + returnObjects on the selector API was losing properties on heterogeneous JSON array elements and inferring unknown for Target. Distribute FilterKeys over unions, ignore phantom optional context keys, and add a dedicated context+returnObjects overload using const Fn inference.
Contributor
Author
|
Review request (API could not assign reviewers from this fork account — please take a look if you have a moment):
Labels intended for this PR (matching the issue): |
adrai
added a commit
that referenced
this pull request
Jun 26, 2026
Member
|
Merged and released in Before merging I verified the change end-to-end:
The |
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.
Summary
Fixes the remaining TypeScript selector regression from #2398:
t(selector, { returnObjects: true, context })on heterogeneous JSON arrays was inferring a union of partial element types (orunknown) instead of preserving full object shapes such as{ transKey1: string; transKey2: string }[].Problem 2 from the issue (valid context keys erroring) was already addressed on master; this PR targets the leftover Problem 1 case and the context + plurals array regression test.
Changes
FilterKeys: distribute over object unions so each JSON array element is filtered independently (avoidskeyof (A | B)only seeing common keys)._DefinedContextKeys/_HasContextVariant/_IsContextualKey: ignore phantom optionalundefinedcontext keys that TypeScript adds when merging heterogeneous array element types (e.g.transKey1_withContext?: undefinedon elements that do not define that key).TFunctionSelector: add a more specific overload forcontext+returnObjects: trueusingconst Context+const Fn+ReturnType<Fn>, matching the non-context selector pattern soTargetis not collapsed viaConstrainTarget/ApplyTarget→unknown.test/typescript/selector-issue-2398/from.todoto realexpectTypeOfassertions (including context + plurals on array elements).Test plan
test/typescript/selector-issue-2398/t.test.tsnpx vitest --config vitest.workspace.typescript.mts run test/typescript/selector-issue-2398npx vitest --config vitest.workspace.typescript.mts run(full TypeScript workspace)test/typescript/selector/still passFixes #2398