Angular – Property does not exist on type

I am new to Angular. I took the following example from a book, to get familiar with javascript classes. I try to load it using main.ts . However, I get the following error: error TS2551: Property ‘_weather’ does not exist on type ‘MyClass’. Did you mean ‘weather’? Can anybody explain me why? It should work, it is a copy/paste from a book. I can make it work if I manually add _weather: string; and name: string; declarations. But it shouldn’t be necessary.

 class MyClass {
        constructor(name, weather) {
            this.name = name;
            this._weather = weather;
        }
        set weather(value) {
            this._weather = value;
        }
        get weather() {
            return `Today is ${this._weather}`;
        }
        printMessages() {
            console.log("Hello " + this.name + ". ");
            console.log(this.weather);
        }
    }
    let myData = new MyClass("Adam", "sunny");
    myData.printMessages();

13 thoughts on “Angular – Property does not exist on type”

  1. 148388 367921Need to tow line this caravan together with van trailer home your entire family fast get exposed towards the issues along with reversing create tight placement. awnings 323720

    Reply

Leave a Comment