sudo apt install npm -y
sudo npm install -g typescript
let hw = "Hello, World!";
console.log(hw);
npx tsc hello.ts
nodejs hello.js
You can use class and interface.
class Student {
fullName: string;
constructor(
public firstName: string,
public middleInitial: string,
public lastName: string
) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
let user = new Student("Jane", "M.", "User");
document.body.textContent = greeter(user);