angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.27k stars 6.71k forks source link

ivy: cdkVirtualForOf template type errors #17411

Closed Splaktar closed 4 years ago

Splaktar commented 4 years ago

Reproduction

Build dev-app with Ivy

Expected Behavior

The demo compiles.

Actual Behavior

ERROR: /Users/splaktar/Git/angular/material2/src/dev-app/virtual-scroll/BUILD.bazel:5:1: Couldn't build file src/dev-app/virtual-scroll/virtual-scroll-demo-module.ngfactory.js: Compiling Angular templates (ngtsc - devmode) //src/dev-app/virtual-scroll:virtual-scroll failed (Exit 1)
src/dev-app/virtual-scroll/virtual-scroll-demo.html(90,8): error TS2322: Type 'number[] | null' is not assignable to type 'number[] | DataSource<number> | Observable<number[]> | Iterable<number> | undefined'.
  Type 'null' is not assignable to type 'number[] | DataSource<number> | Observable<number[]> | Iterable<number> | undefined'.

A fix similar to what was done for ngForOf in PR https://github.com/angular/angular/pull/31371 is also needed for cdkVirtualForOf.

Workaround

Change

<div *cdkVirtualFor="let size of observableData | async; let i = index" class="demo-item [style.height.px]="size">

to

<div *cdkVirtualFor="let size of (observableData | async)!; let i = index" class="demo-item" [style.height.px]="size">

Environment

angular-automatic-lock-bot[bot] commented 4 years ago

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.