Skip to content

Code used inside ICU expressions is not fully type safe/checked. #39064

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

Closed
LastDragon-ru opened this issue Sep 30, 2020 · 4 comments
Closed

Code used inside ICU expressions is not fully type safe/checked. #39064

LastDragon-ru opened this issue Sep 30, 2020 · 4 comments
Labels
area: compiler Issues related to `ngc`, Angular's template compiler area: i18n Issues related to localization and internationalization freq1: low P4 A relatively minor issue that is not relevant to core functions state: confirmed state: has PR type: bug/fix
Milestone

Comments

@LastDragon-ru
Copy link

🐞 bug report

Is this a regression?

Not sure.

Description

Component:

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  value: {a?: {v: number}, b?: {v: number}} = {b: {v: 123}};
}

Code

<!-- This will fail: Object is possibly 'undefined'-->
<p *ngIf="value.b">{{value.a.v}}</p>

<!-- But this will not :( -->
<p *ngIf="value.b">
  {value.a.v, plural, other {...}}.
</p>

Expected behavior:

Both examples must fail with the message "Object is possibly 'undefined'".

Actual behavior:

No errors for {value.a.v, plural, other {...}}.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-ivy-kinrts?file=src%2Fapp%2Fapp.component.html

🌍 Your Environment

Angular CLI: 10.1.3
Node: 13.14.0
OS: linux x64

Angular: 10.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.1001.3
@angular-devkit/build-angular      0.1001.3
@angular-devkit/build-ng-packagr   0.1001.3
@angular-devkit/core               10.1.3
@angular-devkit/schematics         10.1.3
@schematics/angular                10.1.3
@schematics/update                 0.1001.3
ng-packagr                         10.1.2
rxjs                               6.6.3
typescript                         4.0.3

@petebacondarwin petebacondarwin added area: compiler Issues related to `ngc`, Angular's template compiler area: i18n Issues related to localization and internationalization type: bug/fix labels Sep 30, 2020
@ngbot ngbot bot modified the milestone: needsTriage Sep 30, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Sep 30, 2020
@petebacondarwin
Copy link
Contributor

I can confirm that this is happening.

@JoostK
Copy link
Member

JoostK commented Sep 30, 2020

@petebacondarwin I almost have a fix :P

JoostK added a commit to JoostK/angular that referenced this issue Sep 30, 2020
Expressions within ICU expressions in templates were not previously
type-checked, as they were skipped while traversing the elements
within a template. This commit enables type checking of these
expressions by actually visiting the expressions.

Fixes angular#39064
@JoostK JoostK linked a pull request Sep 30, 2020 that will close this issue
@JoostK
Copy link
Member

JoostK commented Sep 30, 2020

I opened a PR but it may need some discussion about needing a strictness flag for backwards compatibility and incremental adoption.

Edit: a quick look at View Engine makes me believe that it did do ICU type checking if fullTemplateTypeCheck is enabled, which may mean that a strictness flag is not needed.

JoostK added a commit to JoostK/angular that referenced this issue Sep 30, 2020
Expressions within ICU expressions in templates were not previously
type-checked, as they were skipped while traversing the elements
within a template. This commit enables type checking of these
expressions by actually visiting the expressions.

Fixes angular#39064
JoostK added a commit to JoostK/angular that referenced this issue Oct 1, 2020
Expressions within ICU expressions in templates were not previously
type-checked, as they were skipped while traversing the elements
within a template. This commit enables type checking of these
expressions by actually visiting the expressions.

Fixes angular#39064
@jelbourn jelbourn added the P4 A relatively minor issue that is not relevant to core functions label Oct 1, 2020
JoostK added a commit to JoostK/angular that referenced this issue Oct 1, 2020
Expressions within ICU expressions in templates were not previously
type-checked, as they were skipped while traversing the elements
within a template. This commit enables type checking of these
expressions by actually visiting the expressions.

Fixes angular#39064
JoostK added a commit to JoostK/angular that referenced this issue Oct 1, 2020
Expressions within ICU expressions in templates were not previously
type-checked, as they were skipped while traversing the elements
within a template. This commit enables type checking of these
expressions by actually visiting the expressions.

Fixes angular#39064
JoostK added a commit to JoostK/angular that referenced this issue Oct 1, 2020
Expressions within ICU expressions in templates were not previously
type-checked, as they were skipped while traversing the elements
within a template. This commit enables type checking of these
expressions by actually visiting the expressions.

Fixes angular#39064
JoostK added a commit to JoostK/angular that referenced this issue Oct 8, 2020
Expressions within ICU expressions in templates were not previously
type-checked, as they were skipped while traversing the elements
within a template. This commit enables type checking of these
expressions by actually visiting the expressions.

BREAKING CHANGE:
Expressions within ICUs are now type-checked again, fixing a regression
in Ivy. This may cause compilation failures if errors are found in
expressions that appear within an ICU. Please correct these expressions
to resolve the type-check errors.

Fixes angular#39064
@atscott atscott closed this as completed in 0a16e60 Oct 8, 2020
@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 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler area: i18n Issues related to localization and internationalization freq1: low P4 A relatively minor issue that is not relevant to core functions state: confirmed state: has PR type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants