Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upfix(core): make QueryList implement Iterable in the type system #33536
+57
−5
Conversation
10fafd5
to
2a35376
This comment has been minimized.
This comment has been minimized.
@alxhub should this change be included in patch branch as well? Thank you. |
LGTM! This would allow me to remove quite a number of |
// there) and this declaration is left here to ensure that TypeScript considers QueryList to | ||
// implement the Iterable interface. This is required for template type-checking of NgFor loops | ||
// over QueryLists to work correctly, since QueryList must be assignable to NgIterable. | ||
[Symbol.iterator] !: () => Iterator<T>; |
This comment has been minimized.
This comment has been minimized.
Splaktar
Nov 3, 2019
Member
Very interesting! For anyone else not completely familiar with using TypeScript Symbols to define class members, here's the docs: https://www.typescriptlang.org/docs/handbook/symbols.html
Originally, QueryList implemented Iterable and provided a Symbol.iterator on its prototype. This caused issues with tree-shaking, so QueryList was refactored and the Symbol.iterator added in its constructor instead. As part of this change, QueryList no longer implemented Iterable directly. Unfortunately, this meant that QueryList was no longer assignable to Iterable or, consequently, NgIterable. NgIterable is used for NgFor's input, so this meant that QueryList was not usable (in a type sense) for NgFor iteration. View Engine's template type checking would not catch this, but Ivy's did. As a fix, this commit adds the declaration (but not the implementation) of the Symbol.iterator function back to QueryList. This has no runtime effect, so it doesn't affect tree-shaking of QueryList, but it ensures that QueryList is assignable to NgIterable and thus usable with NgFor. Fixes #29842
This comment has been minimized.
This comment has been minimized.
Presubmit |
alxhub
added a commit
that referenced
this pull request
Nov 19, 2019
Originally, QueryList implemented Iterable and provided a Symbol.iterator on its prototype. This caused issues with tree-shaking, so QueryList was refactored and the Symbol.iterator added in its constructor instead. As part of this change, QueryList no longer implemented Iterable directly. Unfortunately, this meant that QueryList was no longer assignable to Iterable or, consequently, NgIterable. NgIterable is used for NgFor's input, so this meant that QueryList was not usable (in a type sense) for NgFor iteration. View Engine's template type checking would not catch this, but Ivy's did. As a fix, this commit adds the declaration (but not the implementation) of the Symbol.iterator function back to QueryList. This has no runtime effect, so it doesn't affect tree-shaking of QueryList, but it ensures that QueryList is assignable to NgIterable and thus usable with NgFor. Fixes #29842 PR Close #33536
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.
alxhub commentedNov 1, 2019
Originally, QueryList implemented Iterable and provided a Symbol.iterator
on its prototype. This caused issues with tree-shaking, so QueryList was
refactored and the Symbol.iterator added in its constructor instead. As
part of this change, QueryList no longer implemented Iterable directly.
Unfortunately, this meant that QueryList was no longer assignable to
Iterable or, consequently, NgIterable. NgIterable is used for NgFor's input,
so this meant that QueryList was not usable (in a type sense) for NgFor
iteration. View Engine's template type checking would not catch this, but
Ivy's did.
As a fix, this commit adds the declaration (but not the implementation) of
the Symbol.iterator function back to QueryList. This has no runtime effect,
so it doesn't affect tree-shaking of QueryList, but it ensures that
QueryList is assignable to NgIterable and thus usable with NgFor.
Fixes #29842