Vscode-ng-language-service: Support indexed types

Created on 7 Jul 2017  ·  32Comments  ·  Source: angular/vscode-ng-language-service

When using reactive forms, in the HTML template I get the error in the title.


Please enter a valid name.


Both "formRegister.controls.company.invalid && formRegister.controls.company.touched" are underlined as an error but the app works just fine.

bug

Most helpful comment

I'm also experiencing this issue with reactive forms.

A temporary workaround is to access the property using a bracket propety accessor expression.

formRegister.controls['company'].invalid

All 32 comments

@virgil-av Can you create a repository that reproduces this issue?

We have same issue with union type. Like

public Hour: TimeSpan | string;

Error:
Identifier 'hhMM' is not defined. '' does not contain such a member

hhMM is a valid member in TimeSpan but it seem Hour is treated like a any ;(

@wupaz You example is expected as string does not hhMM as a member and a union type only has the members the constituent types have in common.

TypeScript reports a similar error

I'm also experiencing this issue with reactive forms.

A temporary workaround is to access the property using a bracket propety accessor expression.

formRegister.controls['company'].invalid

Also getting this actually. I believe this used to be an issue in TS as well but seems to be working now for me. At least in TS 2.4.0 and Angular 4.3.0:

Here's the type definition for the FormGroup.controls property: https://github.com/angular/angular/blob/master/packages/forms/src/model.ts#L832

(property) FormGroup.controls: {
    [key: string]: AbstractControl;
}

These both work in TS for me but dot notation complains within the language service:

form.controls['birthday']
form.controls.birthday

@intellix Same here

Same in v2.5.2.

i have the same problem in tsc v2.5.2 as friends said

Can you create a repository that reproduces this issue?

@chuckjaz I can create something better: no repository.

Because I have tested and found that this issue is not related to the source code or npm packages at all. I started having this problem and then tested logging in as a different user, starting visual studio code in the very same directory and then I did not get the error in that editor.

error_screenshot

This is also consistent with that the error only shows up in the editor and the compiler does not complain when building.

So, obviously a per user difference. Then I tested removing the config directory, and the problem went away. When moving the old directory back again the problem re-appears.

$ mv  ~/.config/{,old.}Code
$ code .
$ mv  ~/.config/{,new.}Code
$ mv  ~/.config/{old.,}Code
$ code .

So some cruft has gotten into the config directory that triggers this (some cache would be my guess). When hovering the mouse over valid of name.valid right after starting the editor, a tooltip of "Loading..." displays for several seconds before disappearing and the error occurs. Second time and later, the error is displayed right away when hovering.

I tracked down the user difference, and it is the instalment of the vscode extension Angular.ng-template version 0.1.7. And I can now also provide a repository which reproduces this issue:

  1. Clone https://github.com/colinskow/angular-electron-dream-starter
  2. Apply the attached patch.
  3. Open src/app/hero-form.component.html.
  4. a) With Angular.ng-template installed, name.valid and four other identifiers will get red underlining (and [Angular] Identifier 'valid' is not defined. 'NgModel' does not contain such a member tooltip errors).
    b) With Angular.ng-template not installed or disabled, no errors occur.

The patch is relative to v7.0.0, but I also tested it against commit bd5ad5f0 (Feature/ng2 rc5 (#875)) from 2016-08-21 which is the first commit to contain src/app/app.module.ts, and the error occurred there as well, so I assume this is a problem for all versions of that repo.

Since angular-electron-dream-starter is a fork of https://github.com/AngularClass/angular-starter, I tested the patch in that repo as well, and there the problem does not occur but instead the tooltip contains valid information:

no error

Originally tested on vscode version 1.17.2 (commit b813d129). After updating to version 1.8.0 (commit dcee22027) the result is the same.


Due to Github's utterly stupid attachment handling, the patch is base64 encoded here:

RnJvbSAyYzgxMTJmYzJhM2I2M2FkZjVmZjA0MDQ3NTcyNjAyMjc2ZWMwYmZiIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiA9P1VURi04P3E/SD1DMz1BNWtvbj0yMEw9QzM9Qjh2ZGFsPz0g
PGtvZGVAZGVua3VsZS5ubz4KRGF0ZTogRnJpLCAxNyBOb3YgMjAxNyAyMDozMDoyMCArMDEwMApT
dWJqZWN0OiBbUEFUQ0hdIEltcG9ydCBvZiBleGFtcGxlIGZyb20gaHR0cHM6Ly9hbmd1bGFyLmlv
L2d1aWRlL2Zvcm1zCgotLS0KIHNyYy9hcHAvYXBwLmNvbXBvbmVudC5odG1sICAgICAgIHwgNDAg
KysrKysrKysrKysrKysrKysrKysrKysrKysrCiBzcmMvYXBwL2FwcC5tb2R1bGUudHMgICAgICAg
ICAgICB8ICA1ICsrKy0KIHNyYy9hcHAvaGVyby1mb3JtLmNvbXBvbmVudC5odG1sIHwgNTggKysr
KysrKysrKysrKysrKysr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wdWJsaWMgaWQ6IG51bWJlciwKKwkJcHVibGljIG5hbWU6IHN0cmlu
ZywKKwkJcHVibGljIHBvd2VyOiBzdHJpbmcsCisJCXB1YmxpYyBhbHRlckVnbz86IHN0cmluZwor
CSkgeworCX0KK30KLS0gCjIuMTMuNgoK

I'm facing the similar issue. It appears that plugin only recognizes variables declared directly in the class but not the ones nested under formGroup or formBuilder.
This component code gives error Squigglies in HTML for the two FromControl fields-

export class MyDetailComponent implements OnInit {
  myForm: FormGroup;
  constructor() { }
  ngOnInit() {
    this.myForm = new FormGroup({
      name: new FormControl({ value: '', disabled: true }),
      gender: new FormControl({ value: '', disabled: true })
    });
  }
}

this on the other hand does not give the error squigglies as i have declared FormControl in class directly(this is not a solution unfortunately because angular does not allow formcontrol declaration outside of the formgroup)-

export class MyDetailComponent implements OnInit {
  myForm: FormGroup;
  name: FormControl;
  gender: FormControl;
  constructor() { }
  ngOnInit() {
    this.myForm = new FormGroup({
      name: new FormControl({ value: '', disabled: true }),
      gender: new FormControl({ value: '', disabled: true })
    });
  }
}

Try prepend "!!".
Although it is tricky,
I succeeded this way.

image

@hlovdal I tried your repro steps, but I could not produce the error. It seems to work fine.
I tested using VS Code Linux v1.20.1, Typescript 2.6.2, Angular.ng-template v0.1.9
Can you please confirm if the issue still exists in Angular.ng-template v0.1.9?

@kyliau I ran into this issue today with VS Code v1.21.1 on Windows, Typescript 2.3.4 and Angular.ng-template v0.1.9. Here is how I create the form:

this.form = formBuilder.group({
      amount: ["", Validators.compose([Validators.required, SomeCustomValidator.isValid])],
      sale: [{ value: "0" }],
      amountTotal: [""],
      price: [{ value: "123" }, Validators.compose([Validators.required, SomeCustomValidator.isValid])],
      discount: [{ value: "0" }, SomeCustomValidator.isValid],
      priceAfterDiscount: [""],
      sum: [""],
      sumDph: [""]
 });

and in the template I try to reach for it like this:

<ion-item [class.invalid]="!buyForm.controls.amount.valid && (buyForm.controls.amount.dirty || submitAttempt)">

getting this error:

[Angular] Identifier 'amount' is not defined. '__type' does not contain such a member

When negated, it does not throw the error (meaning that only buyForm.controls.amount.dirty is underlined, not the !buyForm.controls.amount.valid part). That is why the solution given above (with double negation) works.

I have been searching for a workaround to this for ages - thanks

@guhyeon thanks but can you explain what this does?

@rubenheymans
Well ... I don't know that much.
I think it's a type script compiler problem.
It's an expedient that I've learned by accident.

I've tried using this workaround instead, which also stops the vscode Angular Language Service from complaining:

password.hasError('required') using Validators.required validator on password FormControl

AbstractControl.hasError() requires an errorCode value which I had gotten from by displaying the AbstractControl.errors property to the screen for debugging

{{password.errors | json}}, resulting in: { "required": true }

Further typings could probably be available for known errorCodes, as well as custom validators

image

I am also getting the same issue with typescript compiler.

image
image
Same as @ajaysake1992

I think under the hood this is the same issue as #149 -- referencing an object with an index-signature by index (control?.errors['required']) works but referencing with dot-notation (control?.errors.required) is erroneously flagged as incorrect.

I got this today with a simple where 'search' was undefined and was giving me red squiggles.
App compiled and worked as intended (to my frustration after spending half the day trying to solve the squiggly before running it...)
Sounds like a vscode bug to me?

Here's mine work around solution if you don't like the "!!" on html.

your.component.ts :

get emailFormControl(): any {
return this.formGroupName.get('email');
}

your.component.html :

Please Enter a valid email.

This solution works for me, without giving any compile error / runtime error .

Esto me funcionó:
En la línea donde marca el error, hice un espacio con la barra espaciadora antes del cierre de la etiqueta ( >) y el error desapareció.
Borré el espacio creado y quedó todo normal, sin errores.

Also experiencing exactly the same problem. FormGroup controls created in FormBuilder are not known the VSCode's intellisense for the view template. Any idea if there is an actual fix possible for this, rather than the !! workaround

You can use square bracket instead of dot operator to access the property name. This could fix your compilation error.
Example - *ngIf="price.errors[required]"

Wow, brackets does solve the red. I can confirm that this is sporatic.
I'm using Angular: 7.2.15, typescript: 3.1.6 and VSC 1.35.1.
Screen Shot 2019-06-29 at 10 28 28 AM

This is still happening with Angular 8.1.3, with both custom and built-in forms validators (e.g. required). Would be awesome if the registered validators would be clear for intellisense. Running VSC 1.36.1.

Workaround: use bracket annotation instead of dot-annotation, or use !!formcontrol.errors.required

The workaround makes me think if intellisense might mark it due to it's undefined value? Since the errors object is not a set of true/false flags but defined by existence of said flags (which is IMO an unusual pattern), I could imagine intellisense having issues with that.

@ivanwonder have already created PR for this issue. So let's wait until they merge it.

Workaround:

Instead of:

formGroup.errors?.customValidator

use:

formGroup.errors && formGroup.errors['customValidator']

I'm glad there is a workaround... but has any progress been made while investigating the issue?
I'm sure many of us prefer the simple dot notation.

This issue still exists on v0.802.3

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._

Was this page helpful?
0 / 5 - 0 ratings