Typescript TS2339 Property Doesn't Exist On Type - Class Decleration
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.ts class S
Solution 1:
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
Solution 2:
This seems to work fine?
var Student = (function() {
function Student(firstName, middleInitial, lastName) {
this.firstName = firstName;
this.middleInitial = middleInitial;
this.lastName = lastName;
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
return Student;
}());
function greeter(person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
var user = new Student("Jane", "M.", "User");
document.body.innerHTML = greeter(user);
<!-- TYPESCRIPT
var Student = (function () {
function Student(firstName, middleInitial, lastName) {
this.firstName = firstName;
this.middleInitial = middleInitial;
this.lastName = lastName;
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
return Student;
}());
function greeter(person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
var user = new Student("Jane", "M.", "User");
document.body.innerHTML = greeter(user);
-->
Post a Comment for "Typescript TS2339 Property Doesn't Exist On Type - Class Decleration"