question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Property 'controlLabel' does not exist on type 'AbstractControl'. Due to using Ivy!

See original GitHub issue

šŸž bug report

Affected Package

The issue is caused by package @angular/....

Not with certainty

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

Yes: In Angular 8 this issue was not present

Description

When building a form with Reactive Forms I decided to use an extension on FormControl to add a property ā€œcontrolLabelā€ to my formControls, In Version 8 of Angular this works with no problem, however in Angular 9 when I try to read the extra property on my extended class It, the app will not compile and I will receive an error as followed:

ERROR in apps/reactive-forms/src/app/forms/form-with-state-matcher/form-with-state-matcher.component.html:2:12 - error TS2339: Property ā€˜controlLabel’ does not exist on type ā€˜AbstractControl’.

<div>{{form.controls['name'].controlLabel}}</div>

šŸ”¬ Minimal Reproduction

https://stackblitz.com/edit/angular-jg9tyw?file=src%2Fapp%2Fapp.component.ts

I Noticed here that turning off the ā€œUse Ivyā€ flag in the StackBlitz settings tab solves the problem

šŸ”„ Exception or Error




Error in src/app/app.component.html (2:10)
Property 'controlLabel' does not exist on type 'AbstractControl'.

šŸŒ Your Environment

Angular Version:




Angular CLI: 9.1.0
Node: 10.13.0
OS: win32 x64

Angular: 9.1.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.0
@angular-devkit/build-angular     0.901.0
@angular-devkit/build-optimizer   0.901.0
@angular-devkit/build-webpack     0.901.0
@angular-devkit/core              9.1.0
@angular-devkit/schematics        9.1.0
@angular/.cdk.MODULES             <error>
@angular/cdk                      9.2.1
@angular/cli                      9.1.0
@angular/material                 9.2.1
@ngtools/webpack                  9.1.0
@schematics/angular               9.1.0
@schematics/update                0.901.0
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
JoostKcommented, Jul 9, 2020

@samvloeberghs I think you meant to address me (although I do know @joost-de-vries and we live in the same city, I don’t think he’ll respond :p)

The issue as reported here is about template type checking errors that occur in combination with Forms APIs, particularly accessing the property controlLabel from a supposed FormControl. This supposedly did not report an error in earlier versions of Angular, however it has always detected this particular kind of unsafe access provided that AOT compilation is used (template type checking is only done in AOT). So from the compiler’s perspective, there is no bug with the template type checking capability.

The examples you bring up are similar, but the scenario is a bit different given that strictTemplates is enabled. This enables more accurate type checking and as you’ve found out, the Forms API doesn’t really play nicely under these circumstances. The return type of the index signature is AbstractControl, so your knowledge of it actually being a concrete FormControl is not reflected in the Forms’s APIs type design, so the template type checker doesn’t have this knowledge. There’s issues like #36405, #17000, #13721 that request APIs to address this limitation in one way or another.

So although the examples you show are showing errors that may be considered undesirable (I fully agree with you here), they are the result of limitations in the Forms APIs, not limitations or bugs in the type checking machinery. This is why I revoked the confirmed label, as this is not actionable from the compiler’s perspective.

0reactions
angular-automatic-lock-bot[bot]commented, Oct 4, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'controls' does not exist on type 'AbstractControl ...
Based on @Günter Zöchbauer comments , first i changed. myForm.controls['addresses'] to myForm.get('addresses') in both html and typescript.
Read more >
Sam Vloeberghs on Twitter: "Anybody else experiencing this bug ...
Property 'controlLabel' does not exist on type 'AbstractControl'. Due to using Ivy! Ā· Issue #36810... bug report Affected Package The issue is caused...
Read more >
Property 'at' does not exist on type 'AbstractControl - Telerik
1 Answer, 1 is accepted ; kendo-grid-column field="ProductName" title="Product Name" width="250"> ; ng-template kendoGridCellTemplate let-dataItemĀ ...
Read more >
Strictly typed forms in Angular | Ninja Squad
This is great news, as you could previously call it with a key that did not exist, and the compiler would not see...
Read more >
3 steps to make your reactive form typesafe in Angular - LinkedIn
It's great because you can easily manage reactive forms, but it is NOT typesafe. As I learned in the past, typos are easily...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found