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

AoT Compilation not detecting template error #20287

Closed
josephliccini opened this issue Nov 8, 2017 · 13 comments
Closed

AoT Compilation not detecting template error #20287

josephliccini opened this issue Nov 8, 2017 · 13 comments
Labels
area: core Issues related to the framework runtime type: bug/fix
Projects

Comments

@josephliccini
Copy link

I'm submitting a...


[x ] Regression (a behavior that used to work and stopped working in a new release)
[x ] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

A component has public properties, heroTitle: string, v2Layout: boolean.

In template:

<ng-container *ngIf="v2Layout">
    {{ heroTitle }}
</ng-container>

This works, as expected, no error reported.

I will modify template like so:

<ng-container *ngIf="v2Layout">
    {{ heroTitleeeeee }}
</ng-container>

Now, there is no error reported in the AoT compiler, even if I kill the watcher and do a full rebuild.

Furthermore, if one does this:

<!-- <ng-container *ngIf="v2Layout"> -->
    {{ heroTitleeeeee }}
<!-- </ng-container> -->

We get a compilation error in AoT, both in Full Rebuild and Watcher

I am pretty sure this if happening because of *ngIf but no way to be sure. I have seen this in other parts of our application too. On things like [class.foo]="something" if an *ngIf is above it, the compiler won't catch typos, etc.

Expected behavior

I would expect in each case where I am using {{ heroTitleeeeee }} the AoT compiler fails the build.

Minimal reproduction of the problem with instructions

Above

What is the motivation / use case for changing the behavior?

We'd like our AoT builds to be able to detect these errors so that we don't have typos and other issues on our templates before checking in / testing.

Environment

Windows 10


Angular version: 5.0.1


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX   Node 6.9.1
- Platform:   Windows

Others:

@josephliccini
Copy link
Author

Actually I am seeing this on 4.4.4 as well.

Maybe it's related to a TypeScript version? We are using TS 2.4.2

@josephliccini
Copy link
Author

Tried TS 2.5.3 and TS 2.6.1, so unlikely it's a TS issue. Maybe I am not configuring a setting correctly or something..

@vicb vicb added the area: core Issues related to the framework runtime label Nov 8, 2017
@trotyl
Copy link
Contributor

trotyl commented Nov 9, 2017

Can be reproduced in edit.ng directly.

@chuckjaz chuckjaz added this to Prio_col2 in Compiler Nov 10, 2017
@ionathanch
Copy link

ionathanch commented Nov 10, 2017

I'm seeing this issue for *ngFor as well. I tested it with the following:

In app.component.ts:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  public title: string = "app";

  public bool: boolean = true;
  public variableInsideIf: string = "ngIfTest";

  public list: number[] = [1, 1, 2, 3, 5, 8, 13];
  public variableInsideFor: string = "ngForTest";
}

In app.component.ng.html:

<div style="text-align:center">
  <div>
    {{title}}
  </div>
  <div *ngIf="bool">
    {{variableInsideIf}}
  </div>
  <div *ngFor="let n of list">
    {{variableInsideFor}} {{n}}
  </div>
</div>

If I change {{title}} to {{titleeee}} or {{title.dummy}}, I get the compilation error, but if I change {{variableInsideIf}} to {{variableInsideIffff}} or {{variableInsideFor}} to {{variableInsideForrrr}} or {{n}} to {{n.dummy}} I don't get the error.

I also tried compiling with ngc using @angular/compiler-cli@4.4.6, and this is what I see in the generated app.component.ngfactory.ts:

...
var _co:any = _v.component;
const currVal_0:any = _co.variableInsideIf;
...
var _co:any = _v.component;
const currVal_0:any = _co.variableInsideFor;
const currVal_1:any = _v.context.$implicit;
...
var _co:i3.AppComponent = _v.component;
const currVal_1:any = _co.bool;
const currVal_2:any = _co.list;
...
var _co:i3.AppComponent = _v.component;
const currVal_0:any = _co.title;

As you can see, when accessing title, _co has the correct type annotation of AppComponent, but when accessing variableInsideIf or variableInsideFor, _co has the type annotation of any instead, which is probably why the error isn't being caught on compilation. Additionally, the n inside the for loop corresponds here to _v.context.$implicit, but its type isn't checked anywhere, so changing {{n}} to {{n.dummy}} yields _v.context.$implicit.dummy which doesn't fail but I believe should, since we can trace that n is from list is from AppComponent, and it does fail for title.dummy.

Edit: This angular/angular-cli#5764 might also be related?

@BorntraegerMarc
Copy link

@trotyl the provided link doesn't work anymore 😉

@trotyl
Copy link
Contributor

trotyl commented Nov 26, 2017

@BorntraegerMarc fixed, just mean it literally.

@mbx-mbx
Copy link

mbx-mbx commented Dec 5, 2017

Same issue here when using *ngIf.

@mhevery
Copy link
Contributor

mhevery commented Dec 5, 2017

This is a know bug which we are working on fixing right now.

Duplicate of #19792

@mhevery mhevery closed this as completed Dec 5, 2017
@josephliccini
Copy link
Author

Thanks @mhevery !

fwiw with issues like #19792 it might be good to put a brief summary for those outside Google just so we don't duplicate bugs in your bug tracker 😄

@lichunr
Copy link

lichunr commented Jan 4, 2019

any update on this one? we're still facing this issue, thanks

@vanslly
Copy link

vanslly commented Jun 27, 2019

@lichunr For some additional template type checking you should set fullTemplateTypeCheck = true in your tsconfig.json: https://angular.io/guide/aot-compiler#fulltemplatetypecheck

Template type checking is still poor, but is improved with Renderer 3 (Ivy). Even with Angular 8 with Renderer 3 you still need to set fullTemplateTypeCheck = true and in the future this will be on by default. Only reason it's not on by default is for backwards compatibility.

@lichunr
Copy link

lichunr commented Jun 27, 2019

@vanslly Thx for the solution!

@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 Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime type: bug/fix
Projects
No open projects
Compiler
  
Prio_col2
Development

No branches or pull requests

10 participants