Search code examples
typescripttypescript-class

Using Private Properties in TypeScript Class (Value Never Used)


Here is the code I am using:

class ProjectInput {
    private templateElement: HTMLTemplateElement;
    private hostElement: HTMLDivElement;

    constructor() {
        this.templateElement = document.getElementById('project-input')! as HTMLTemplateElement;
        this.hostElement = document.getElementById('app')! as HTMLDivElement;
    }
}

I am receiving this error when I try to compile it:

enter image description here

I am using the properties already in the constructor. If I removed the private modifier, no errors are generated. I still need to declare them as private though.


Solution

  • You say you are using these variable in the constructor, but you are not. You are declaring them, but not using them. At this time, those variable do seem useless. If you don't plan on using them any further, then they should just be deleted.