Skip to content
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

fix(common): reflect input type in context #33997

Closed
wants to merge 2 commits into from

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Nov 22, 2019

Fixes NgForOf not reflecting the type of its input in the NgForOfContext. Also fixes NgIf which was typed to any.

Fixes #33527.
Fixes #31556.

@crisbeto crisbeto force-pushed the FW-1738/ngfor-input-type branch 2 times, most recently from 4d4e404 to adf9934 Compare November 22, 2019 22:02
@crisbeto crisbeto added area: common Issues related to APIs in the @angular/common package action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release labels Nov 22, 2019
@ngbot ngbot bot modified the milestone: needsTriage Nov 22, 2019
@crisbeto crisbeto marked this pull request as ready for review November 22, 2019 22:23
@crisbeto crisbeto requested review from a team as code owners November 22, 2019 22:23
@IgorMinar
Copy link
Contributor

presubmit
ivy presubmit

@IgorMinar IgorMinar added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 26, 2019
Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

can you please split this into two commits and document each change and what is the user-facing fix/impact because when users read about this change in the changelog they will not have any idea about what this does, or mean to them.

I'm assuming that this is a fix for #33527. Can you please state that in the commit message?

Lastly, any chance we we can add some tests for this? I'm assuming that we currently don't have any good infra to test typechecking changes like this unless we write a ngtsc specific test. Is that right?

I've kicked off a presubmit for this change in the meantime to make sure that there are no surprises.

@IgorMinar IgorMinar added target: patch This PR is targeted for the next patch release and removed target: major This PR is targeted for the next major release labels Nov 26, 2019
@IgorMinar
Copy link
Contributor

IgorMinar commented Nov 26, 2019

also, this should target the 9.0.x branch as well because otherwise we won't be able to roll this out until v10. (I updated the target label)

Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

Regarding tests, I think the most valuable way would still be ngtsc's template type checking tests. I feel this way because those tests exercise real Angular templates.

As an alternative, a test could mimic the code that the type checker generates, as to assert that type inference works as expected. Such tests however are most appropriate to be run using https://github.com/microsoft/dtslint, which we don't currently have anywhere AFAIK. Also, I would consider them brittle as there's no guarantee that they are accurate, hence my preference for actual ngtsc template type checking tests.

packages/common/src/directives/ng_for_of.ts Show resolved Hide resolved
packages/common/src/directives/ng_if.ts Show resolved Hide resolved
packages/common/src/directives/ng_if.ts Outdated Show resolved Hide resolved
@crisbeto crisbeto removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 26, 2019
@crisbeto
Copy link
Member Author

I've addressed the feedback. Can you take another look @JoostK @IgorMinar?

JoostK
JoostK previously requested changes Nov 27, 2019
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

I would love to see template type checker tests. If you need help with that, please let me know.

private _thenTemplateRef: TemplateRef<NgIfContext<T>> = null !;
private _elseTemplateRef: TemplateRef<NgIfContext<T>> = null !;
private _thenViewRef: EmbeddedViewRef<NgIfContext<T>> = null !;
private _elseViewRef: EmbeddedViewRef<NgIfContext<T>> = null !;
Copy link
Member

Choose a reason for hiding this comment

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

All these private fields can keep the | null, as it keeps the implementation safe against nulls.

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

fyi: g3 is looking good. @crisbeto can you please address Joost's feedback?

@IgorMinar IgorMinar added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 27, 2019
@crisbeto
Copy link
Member Author

I have all the feedback addressed locally, but it uncovered some issues with the new signatures. I'll pair up with Joost tomorrow.

Fixes `NgForOf` not reflecting the type of its input in the `NgForOfContext`.
@crisbeto crisbeto requested a review from a team as a code owner November 28, 2019 18:47
@crisbeto
Copy link
Member Author

All the issues and feedback should addressed now. Thank you for the help with the tests @JoostK!

@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 28, 2019
Copy link
Member

@JoostK JoostK left a comment

Choose a reason for hiding this comment

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

In the NgIf commit, could you include a fixes note for #31556?

packages/common/src/directives/ng_if.ts Outdated Show resolved Hide resolved
Fixes the content of `NgIf` being typed to any.

Fixes angular#31556.
@crisbeto
Copy link
Member Author

Done.

@JoostK JoostK dismissed their stale review December 2, 2019 09:32

addressed

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Dec 2, 2019
mhevery pushed a commit that referenced this pull request Dec 2, 2019
Fixes `NgForOf` not reflecting the type of its input in the `NgForOfContext`.

PR Close #33997
mhevery pushed a commit that referenced this pull request Dec 2, 2019
Fixes the content of `NgIf` being typed to any.

Fixes #31556.

PR Close #33997
@mhevery mhevery closed this in a6b6d74 Dec 2, 2019
mhevery pushed a commit that referenced this pull request Dec 2, 2019
Fixes the content of `NgIf` being typed to any.

Fixes #31556.

PR Close #33997
crisbeto added a commit to crisbeto/angular that referenced this pull request Dec 3, 2019
This is a follow-up to angular#33997 where some new generic parameters were added without defaults which is technically a breaking change. These changes add the defaults.
crisbeto added a commit to crisbeto/angular that referenced this pull request Dec 3, 2019
This is a follow-up to angular#33997 where some new generic parameters were added without defaults which is technically a breaking change. These changes add the defaults.
crisbeto added a commit to crisbeto/angular that referenced this pull request Dec 3, 2019
This is a follow-up to angular#33997 where some new generic parameters were added without defaults which is technically a breaking change. These changes add the defaults.
mhevery pushed a commit that referenced this pull request Dec 4, 2019
This is a follow-up to #33997 where some new generic parameters were added without defaults which is technically a breaking change. These changes add the defaults.

PR Close #34206
mhevery pushed a commit that referenced this pull request Dec 4, 2019
This is a follow-up to #33997 where some new generic parameters were added without defaults which is technically a breaking change. These changes add the defaults.

PR Close #34206
@Splaktar
Copy link
Member

Splaktar commented Dec 17, 2019

It seems like there should be a test for how this typing behaves with *ngIf="something | async; let thing". In that case, the behavior here doesn't seem to align with one of the most common use cases of *ngIf.

@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 Jan 17, 2020
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 area: common Issues related to APIs in the @angular/common package cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ivy: fullTemplateTypeCheck errors with NgIterable Type check directive template context
6 participants