Skip to content

ListKeyManager activeItem property has wrong type #14152

Closed
@szymonbultrowicz

Description

@szymonbultrowicz

Bug, feature request, or proposal:

ListKeyManager activeItem property has a wrong type

What is the expected behavior?

The activeItem property can be undefined in some cases, so the typing should be aware of the undefined as well. Another way would be to handle undefined value and return null then.

What is the current behavior?

The activeItem type is set to T | null, but happens to return undefined.

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material-ticket-active-item-type

What is the use-case or motivation for changing an existing behavior?

In some cases (no value selected, non-existing value selected) the property can be also undefined which is not suggested by typing. Due to that fact, we recently faced a null pointer exception, because we only handled null value.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

It affects @angular/cdk in version 6.3.0+ for sure, although it looks like the code is quite old, so previous version are probably affected as well.

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions