Skip to content

Instantly share code, notes, and snippets.

@kuzmicheff
Created September 16, 2017 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuzmicheff/aee79e966596d3242f897b8a6e6000b8 to your computer and use it in GitHub Desktop.
Save kuzmicheff/aee79e966596d3242f897b8a6e6000b8 to your computer and use it in GitHub Desktop.
Simple greeter in TypeScript
<html>
<head>
<title>TypeScript Greeter</title>
</head>
<body>
<script src="greeter.js"></script>
</body>
</html>
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("Andre", "N", "Kuzmicheff");
document.body.innerHTML = greeter(user);
class Student {
fullName: string;
constructor(public firstName, public middleInitial, public lastName) {
this.fullName = firstName + " " + middleInitial + " " + lastName;
}
}
interface Person {
firstName: string;
lastName: string;
}
function greeter(person: Person) {
return "Hello, " + person.firstName + " " + person.lastName;
}
var user = new Student("Andre", "N", "Kuzmicheff");
document.body.innerHTML = greeter(user);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment