Repository navigation
Conversation
A numeric index signature is not an open set of keys. Emit patternProperties for "^[0-9]+$" and keep additionalProperties for a string index when both signatures are present.
An intersection of two numeric index signatures must satisfy both value schemas. Combine a shared pattern key with allOf instead of keeping only one side.
… as objects allOf of two closed object schemas rejects a property that exists on only one side. Merge object-valued numeric indexes with the existing object intersection, and keep Partial of a numeric index as an object.
A $ref pattern value is not an object schema, so the intersection fell through to allOf and the closed base rejected properties added by the derived type. Resolve those refs to their object schemas before merging.
An intermediate interface stores a cloned pattern $ref, which drops the WeakMap back to the named object. Reattach that source so the next merge can still resolve it.
Cloning an object schema dropped WeakMap metadata on nested pattern $refs, so an inner numeric index fell back to allOf. Reattach those sources on every nested schema in the merge clones.
Merging a numeric index that refers to itself resolved the same $ref pair forever. When that pair is already being merged, keep the ref or fall back to allOf.
|
Did you manually review the code in this pull request? |
|
Thanks for asking. Yes, though I should be upfront: the code was written with AI assistance, and I ran it through an AI review before opening the PR. I've since gone through the changes myself and can explain any part of it. Two known limitations remain with recursive types: mixed recursive nesting (e.g. |
Closes #2134
What
{ [index: number]: T }(andRecord<number, T>) used to produceadditionalProperties: T, which also accepts non-numeric keys. A numeric index now produces:{ "type": "object", "additionalProperties": false, "patternProperties": { "^[0-9]+$": T } }additionalProperties, and the numeric index only narrows^[0-9]+$.Record<string | number, T>staysadditionalProperties: T, because both key kinds share one value type.src/Utils/indexSignature.ts, and the mapped-type,keyof, intersection andallOfpaths are updated to carrypatternPropertiesthrough.Behaviour change
The output for numeric-keyed maps changes.
test/valid-data/type-mapped-number/schema.jsonis updated to match. Let me know if you'd rather put this behind an option or treat it as a breaking change.Testing
test/valid-data/numeric-index-signaturenpm run build,npm run lint(no new warnings) andnpm test(380 passed) all succeed.