Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

X is declared but its value is never read. Though I have used the variable

I’m using some properties in my Angular component, but I’m getting the following warnings in VSCode:

'_id' is declared but its value is never read.ts(6133)
(property) ItemEditComponent._id: number | undefined

'_isModeEdit' is declared but its value is never read.ts(6133)
(property) ItemEditComponent._isModeEdit: boolean

This is also my component:

import { Component, OnDestroy, OnInit, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ActivatedRoute, Params } from '@angular/router';
import { Subscription } from 'rxjs';

@Component({
  selector: 'app-item-edit',
  standalone: true,
  imports: [CommonModule],
  templateUrl: './item-edit.component.html',
  styleUrls: ['./item-edit.component.scss'],
})
export class ItemEditComponent implements OnInit, OnDestroy {
  private _route = inject(ActivatedRoute);
  private _routeParamsSub: Subscription = new Subscription();

  private _id: number | undefined = undefined;  // I'm getting the warning for this variable!
  private _isModeEdit = false;                  // And this one!

  ngOnInit(): void {
    this._routeParamsSub = this._route.params.subscribe((params: Params) => {
      this._initPage(+params['id']);
    });
  }

  ngOnDestroy(): void {
    this._routeParamsSub.unsubscribe();
  }

  _initPage(id: number | undefined) {
    if (!id) return;
    this._id = id;
    this._isModeEdit = true;
  }
}

As you can see, I’m actually using the variables! Any ideas why I’m seeing such warnings? Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are not using the variables. Assignment isn’t using

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading