Skip to content

fix(cdk/scrolling): expand type for "cdkVirtualForOf" input to work with strict null checks #17421

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

Conversation

devversion
Copy link
Member

Currently the cdkVirtualForOf input accepts null or undefined as valid values. Although
when using strict template input type checking (which will be supported by ngtsc), passing
null or undefined causes a type check failure because the type definition of the input becomes
too explicit with "--strictNullChecks" enabled.

For extra content: by default if strict null checks are not enabled, null or undefined
are assignable to every type. The current type definiton of the cdkVirtualForOf input
is incorrectly making the assumption that null or undefined are always assignable.

The type of the input needs to be expanded to explicitly accept null or
undefined to behave consistently regardless of the strictNullChecks flag.

This is similar to what we did for ngFor in framework: angular/angular@c1bb886

Fixes #17411

@devversion devversion added the target: major This PR is targeted for the next major release label Oct 16, 2019
@devversion devversion added this to the 9.0.0 milestone Oct 16, 2019
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 16, 2019
@devversion devversion added the P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful label Oct 16, 2019
…ith strict null checks

Currently the `cdkVirtualForOf` input accepts `null` or `undefined` as valid
values. Although when using strict template input type checking
(which will be supported by `ngtsc`), passing `null` or `undefined`
with strict null checks enabled causes a type check failure because
the type definition of the input becomes too strict with "--strictNullChecks" enabled.

For extra content: by default if strict null checks are not enabled, `null` or `undefined`
are assignable to _every_ type. The current type definiton of the `cdkVirtualForOf` input
is incorrectly making the assumption that `null` or `undefined` are always assignable.

The type of the input needs to be expanded to explicitly accept `null` or
`undefined` to behave consistently regardless of the `strictNullChecks` flag.

A common scenario where this breaks is the use of `cdkVirtualFor` in combination
with the async pipe from `@angular/common`. This is because the async pipe returns
`null` until a value has been emitted. This means that with strict null checks, the type
checking will fail because `null` is not allowed.

This is similar to what we did for `ngFor` in framework: angular/angular@c1bb886

Fixes angular#17411
@devversion devversion force-pushed the fix/cdk-scorlling-expand-type-cdk-virtual-for-of branch from bce5f38 to 1ba5d2d Compare October 16, 2019 14:04
@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Oct 16, 2019
@mmalerba mmalerba merged commit 3e5e9db into angular:master Oct 16, 2019
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P1 Impacts a large percentage of users; if a workaround exists it is partial or overly painful target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ivy: cdkVirtualForOf template type errors
3 participants