Skip to content

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

Closed
crisbeto wants to merge 2 commits into
angular:masterfrom
crisbeto:FW-1738/ngfor-input-type
Closed

crisbeto wants to merge 2 commits into
angular:masterfrom
crisbeto:FW-1738/ngfor-input-type

Conversation

@crisbeto

@crisbeto crisbeto commented Nov 22, 2019 •

Copy link
Copy Markdown
Member

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 November 22, 2019 22:23
@IgorMinar

Copy link
Copy Markdown
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

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

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

IgorMinar commented Nov 26, 2019 •

Copy link
Copy Markdown
Contributor

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)

@JoostK JoostK left a comment

Copy link
Copy Markdown
Member

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.

Comment thread packages/common/src/directives/ng_if.ts Resolved
Comment thread packages/common/src/directives/ng_if.ts Resolved
@crisbeto
crisbeto force-pushed the FW-1738/ngfor-input-type branch from adf9934 to 42c316d Compare November 26, 2019 19:58
@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
Copy Markdown
Member Author

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

@crisbeto
crisbeto force-pushed the FW-1738/ngfor-input-type branch from 42c316d to df1e844 Compare November 26, 2019 20:06
JoostK
JoostK previously requested changes Nov 27, 2019

@JoostK JoostK left a comment

Copy link
Copy Markdown
Member

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.

Comment thread packages/common/src/directives/ng_if.ts Outdated

Copy link
Copy Markdown
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.

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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 force-pushed the FW-1738/ngfor-input-type branch from df1e844 to ac43930 Compare November 28, 2019 18:47
@crisbeto
crisbeto requested a review from a team November 28, 2019 18:47
@crisbeto

Copy link
Copy Markdown
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

@JoostK JoostK left a comment

Copy link
Copy Markdown
Member

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?

Comment thread packages/common/src/directives/ng_if.ts Resolved
Fixes the content of `NgIf` being typed to any.

Fixes angular#31556.
@crisbeto
crisbeto force-pushed the FW-1738/ngfor-input-type branch from ac43930 to 66e8ed4 Compare November 29, 2019 22:11
@crisbeto

Copy link
Copy Markdown
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.
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

Splaktar commented Dec 17, 2019 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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