Skip to content

fix: preserve array and tuple structure in mapped types#2515

Open
puckey wants to merge 2 commits into
vega:nextfrom
puckey:fix/mapped-type-array-tuple
Open

fix: preserve array and tuple structure in mapped types#2515
puckey wants to merge 2 commits into
vega:nextfrom
puckey:fix/mapped-type-array-tuple

Conversation

@puckey

@puckey puckey commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Summary

  • When a mapped type like { [K in keyof T]: F<T[K]> } operates on an array or tuple, TypeScript preserves the array/tuple structure, but the schema generator produced objects with numeric string keys
  • Detect keyof constraint resolving to number (array) and produce ArrayType
  • Detect keyof constraint resolving to numeric literal union (tuple) and produce TupleType

Test plan

  • type-immutable-arrayImmutable<Bar[]> produces array schema, Immutable<[string, number]> produces tuple schema, Immutable<Bar> with Map/Set branches resolves correctly
  • All existing tests pass

Comment thread test/config/type-immutable-array/tsconfig.json Outdated
@puckey puckey force-pushed the fix/mapped-type-array-tuple branch from 1742864 to 5dd665f Compare March 31, 2026 07:11
When a mapped type like `{ [K in keyof T]: F<T[K]> }` operates on an
array or tuple, TypeScript preserves the array/tuple structure. The
schema generator was instead producing objects with numeric string keys.

- Detect `keyof` constraint resolving to `number` (array) and produce ArrayType
- Detect `keyof` constraint resolving to numeric literal union (tuple) and
  produce TupleType
@puckey puckey force-pushed the fix/mapped-type-array-tuple branch from 5dd665f to 2f21153 Compare March 31, 2026 07:18
@puckey

puckey commented Mar 31, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on next and ran tests.

@puckey puckey requested a review from arthurfiorette April 2, 2026 18:38
@arthurfiorette

Copy link
Copy Markdown
Collaborator

@puckey CI is failing

@arthurfiorette arthurfiorette added the feedback Waiting for feedback resolution label Jun 18, 2026
@puckey

puckey commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the prettier lint error in MappedTypeNodeParser.ts (5061f19).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feedback Waiting for feedback resolution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants