Typescript TS2339 Property doesn't exist on type - Class decleration

前端 未结 2 1577
孤独总比滥情好
孤独总比滥情好 2021-01-26 23:07

I am using exact example outlined in Typescript https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html#classes

This is exact copy I am running in app

2条回答
  •  半阙折子戏
    2021-01-26 23:28

    You are declaring some public properties of your class directly in the consctructor so you should use "this" keyword

    class Student {
        fullName: string;
        constructor(public firstName, public middleInitial, public lastName) {
            this.fullName = this.firstName + " " + this.middleInitial + " " + this.lastName;
        }
    }
    

    Edit : working fiddle

提交回复
热议问题