Repository navigation
fix(forms): return a numeric keyInParent for array items - #71617
Open
fabioemoutinho wants to merge 1 commit into
Open
fabioemoutinho wants to merge 1 commit into
fabioemoutinho wants to merge 1 commit into
Conversation
`FieldState.keyInParent` is typed as `number` for children of an array field and documented as the index in that array, but it returned the string property key (e.g. `'1'`) because child keys come from `Object.keys()`. Comparisons like `i !== item().keyInParent()` then type-check but never match. Convert the key to a number when the parent value is an array. Object property keys are unchanged, as are the internal string keys used for `pathKeys` and `FieldContext.key`. Fixes angular#71616
Contributor
Author
|
@alxhub I found your commit bb6d010 ("align runtime type of I don't see it in a PR yet. If you plan to land that version, I'm happy to close this one. Otherwise, let me know if you'd like this PR changed to match your approach. |
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.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
FieldState.keyInParent()is typedSignal<TKey>withTKey = numberfor children of an array field, and documented as the index in that array, but at runtime it returns the string property key ('1'), since child keys come fromObject.keys(). Code likei !== item().keyInParent()type-checks but never matches.Issue Number: #71616
What is the new behavior?
For children of an array field,
keyInParent()returns the index as a number, matching the declared type and the JSDoc. Object property keys are still strings. The internal string keys (used forpathKeysandFieldContext.key) are unchanged; this follows the same conversionFieldContext.indexalready does.The issue also mentions the other option (changing the type to
string), in case that's preferred.Does this PR introduce a breaking change?
Code that relied on the undocumented string value (e.g.
=== '1') would see a number instead, but that contradicts the declared type.Other information
Fixes #71616