Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

build: enable strictPropertyInitialization #689

Merged
merged 1 commit into from
Mar 18, 2021

Conversation

Splaktar
Copy link
Contributor

@Splaktar Splaktar commented Dec 14, 2019

  • fix related build errors
  • complete this._destroyed in ngOnDestroy()
  • replace use of deprecated DomPortalHost with DomPortalOutlet

Builds on PR #688

@Splaktar Splaktar self-assigned this Dec 14, 2019
@Splaktar Splaktar force-pushed the strictPropertyInitialization branch from 87a640c to d188ae4 Compare December 14, 2019 22:05
@Splaktar Splaktar requested a review from crisbeto December 14, 2019 22:09
@Splaktar
Copy link
Contributor Author

Splaktar commented Dec 14, 2019

@crisbeto can you please take a look at this Circle CI error? It seems to be related to the Portal Changes in 9.0.0.

Should I file a bug here or is there some misconfiguration in this PR?

Edit: ✅ solved

@Splaktar Splaktar force-pushed the strictPropertyInitialization branch from d188ae4 to 7109a0d Compare December 16, 2019 17:56
@Splaktar Splaktar requested review from jelbourn and removed request for crisbeto December 16, 2019 18:08
@Splaktar Splaktar force-pushed the strictPropertyInitialization branch from 7109a0d to f919ec8 Compare December 16, 2019 22:28
@Splaktar Splaktar changed the title build: enable strictPropertyInitialization build: enable strictPropertyInitialization and update CI Dec 17, 2019
@Splaktar
Copy link
Contributor Author

Splaktar commented Dec 17, 2019

I just found that this branch/PR were passing on CircleCI, but failing to build locally. It appears that ng test doesn't expose Ivy's Template Type Checking errors. However, Template Type Checking does break the build. So I've added a build task to CI to catch this issue.

Note that these Template Type Checking errors are new in Angular 9.0.0-rc.6. In the previous build based on 9.0.0-rc.4, they did not appear.

Additionally, it also runs build:content to ensure that the docs-content can be synced as we've had a couple issues this year where that was broken and we weren't aware of it immediately.

@Splaktar
Copy link
Contributor Author

Splaktar commented Dec 17, 2019

OK, the issues that I'm hitting were introduced in Angular 9.0.0-rc.5 as part of PR angular/angular#33997 (specifically angular/angular@66e8ed4) which was fixing angular/angular#31556. Prior to that change, template variables created as part of an *ngIf="something | async; let thing" were always of type any (i.e. thing: any). However, they are now typed and will throw errors due to strict Template Type Checking.

I'm investigating how to solve them, but I don't feel like my current solution is solid, so I'm continuing to investigate.

@Splaktar Splaktar requested a review from crisbeto December 17, 2019 01:20
@Splaktar
Copy link
Contributor Author

@crisbeto or @JoostK do you have any guidance here?

Template

<ng-container *ngIf="componentViewer.componentDocItem | async; let docItem">
  <span class="cdk-visually-hidden" tabindex="-1" #initialFocusTarget>
    Examples for {{docItem.id}}
  </span>
  <example-viewer *ngFor="let example of docItem.examples"
                  [example]="example"></example-viewer>
</ng-container>

There are errors for

src/app/pages/component-viewer/component-examples.html:3:20 - error TS2531: Object is possibly 'null'.

3     Examples for {{docItem.id}}
                     ~~~~~~~~~~

  src/app/pages/component-viewer/component-viewer.ts:132:16
    132   templateUrl: './component-examples.html',
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component ComponentExamples.
src/app/pages/component-viewer/component-examples.html:5:34 - error TS2531: Object is possibly 'null'.

5   <example-viewer *ngFor="let example of docItem.examples" [example]="example"></example-viewer>
                                   ~~~~~~~~~~~~~~~~

  src/app/pages/component-viewer/component-viewer.ts:132:16
    132   templateUrl: './component-examples.html',
                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Error occurs in the template of component ComponentExamples.

Solutions?

It's complaining about docItem.id and docItem.examples where docItem might be null in these cases. But it seems to be ignoring the fact that this template won't be rendered if docItem is null.

The tests in PR angular/angular#33997 don't cover the use case where the Async Pipe is used.

How do you recommend developers solve this very common use case?

@JoostK
Copy link
Member

JoostK commented Dec 17, 2019

@Splaktar ah, this is interesting. Using as the way we tested it reflects the NgIfContext.ngIf property, for which the template type checker has applied the appropriate context guard expression due to the presence of NgIf.ngContextGuard_ngIf.

When used with a let assignment to $implicit, however, the context guard for ngIf does not narrow reads of $implicit.

I'll have a look to see if there's something that can be done here.

@Splaktar
Copy link
Contributor Author

@JoostK I tried the following and got the same errors:

<ng-container *ngIf="componentViewer.componentDocItem | async as docItem">

@Splaktar
Copy link
Contributor Author

Splaktar commented Dec 19, 2019

@JoostK here is the workaround that I had to apply to get our repo building again after the breaking change in Angular 9.0.0-rc.5.

Do you have an open GitHub issue to track this or should I open one? I wasn't able to find one after looking through the Angular issues.

@Splaktar Splaktar force-pushed the strictPropertyInitialization branch 4 times, most recently from d01f9c8 to 58b2166 Compare January 30, 2021 07:31
@Splaktar Splaktar force-pushed the strictPropertyInitialization branch from 58b2166 to 43e17cd Compare March 1, 2021 19:34
Splaktar added a commit to DevIntent/material.angular.io that referenced this pull request Mar 1, 2021
@Splaktar
Copy link
Contributor Author

Splaktar commented Mar 1, 2021

PR #926 reverts the workarounds, mentioned above, to get the builds working with the async pipe type narrowing bug.

@Splaktar Splaktar force-pushed the strictPropertyInitialization branch 2 times, most recently from ca3527b to bbdd1e1 Compare March 1, 2021 20:09
Splaktar added a commit that referenced this pull request Mar 1, 2021
- fix related build errors
- complete `this._destroyed` in `ngOnDestroy()`
- replace use of deprecated `DomPortalHost` with `DomPortalOutlet`
@Splaktar Splaktar force-pushed the strictPropertyInitialization branch from bbdd1e1 to 6e305c5 Compare March 1, 2021 20:11
@Splaktar
Copy link
Contributor Author

Splaktar commented Mar 1, 2021

@jelbourn this is the PR I mentioned in the meeting and you said that you would take a quick look at. This would get us closer to being aligned with the Angular CLI's strict mode.

Copy link
Collaborator

@andrewseguin andrewseguin left a comment

Choose a reason for hiding this comment

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

LGTM

@andrewseguin andrewseguin merged commit 41738f3 into master Mar 18, 2021
@Splaktar Splaktar deleted the strictPropertyInitialization branch March 18, 2021 21:21
alexeagle pushed a commit to alexeagle/material2 that referenced this pull request Nov 6, 2024
alexeagle pushed a commit to alexeagle/material2 that referenced this pull request Dec 12, 2024
alexeagle pushed a commit to alexeagle/material2 that referenced this pull request Dec 16, 2024
alexeagle pushed a commit to alexeagle/material2 that referenced this pull request Dec 18, 2024
josephperrott pushed a commit to angular/components that referenced this pull request Dec 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants