Skip to content

fix(material/table): return undefined sort and paginator #31593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rslawik
Copy link
Contributor

@rslawik rslawik commented Jul 24, 2025

The initial value for sort and paginator is undefined and since #31269 the setter accepts undefined too (typically from a signal child query). This change aligns the getter type with the real type and makes it symmetric with the setter.

The initial value for `sort` and `paginator` is `undefined` and since angular#31269 the setter accepts
`undefined` too (typically from a signal child query).
This change aligns the getter type with the real type and makes it symmetric with the setter.
@rslawik rslawik requested a review from a team as a code owner July 24, 2025 09:18
@rslawik rslawik requested review from crisbeto and wagnermaciel and removed request for a team July 24, 2025 09:18
@@ -103,18 +103,16 @@ export class MatTableDataSource<T, P extends MatPaginator = MatPaginator> extend
* Instance of the MatSort directive used by the table to control its sorting. Sort changes
* emitted by the MatSort will trigger an update to the table's rendered data.
*/
get sort(): MatSort | null {
get sort(): MatSort | null | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a public API change. It might be better to change the setter to || null so the runtime matches the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got LGTM from @andrewseguin to proceed in this direction. I already prepared google3 for that. It was easy - 3 places where the type was explicitly copied.

Given that it always could have returned undefined, there may be code handling that. A breaking compile time check is safer than changing runtime behavior. Coalescing to null caught tests in google3 that expected that what they put in is what they get back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change aligns closer to what is actually happening, since sort actually can return undefined when its unset. Since this expands the set rather than constricting, I don't know if this counts as a major "breaking" change.

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

Successfully merging this pull request may close these issues.

3 participants