JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<h1>TypeScript Example</h1>
<h2>Open your console</h2>
</body>
TypeScript
class Employee {
name:string;
surname:string;
age:number;
position:string;
constructor({name, surname, age, position="Developer"}: {name:string; surname:string; age:number; position?:string}) {
this.name = name;
this.surname = surname;
this.age = age;
this.position = position;
}
greeter() {
console.log("Hello " + this.name + " " + this.surname);
}
}
class Developer extends Employee {
yearsOfSeniority: number;
salary: number;
isExperienced() {
return (this.yearsOfSeniority >=3) ? "You are experienced" : "You are newbie";
}
greeter() {
console.log("Hi " + this.name + ", " + this.isExperienced() + " developer. You earn " + this.salary + " PLN.");
}
}
var first:Developer = new Developer({name: "Tomasz", surname:"Hencel", age: 23, position: "Developer"});
var second:Employee = new Employee({name: "John", surname: "Example", age: 33});
first.salary: 6000;
first.yearsOfSeniority = 3;
console.log(first.isExperienced());
first.greeter();