Last active
March 6, 2019 12:57
-
-
Save elvisciotti/639c44a39a89db2fec0f5e3c9ec17548 to your computer and use it in GitHub Desktop.
typscript class and interface compile example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.innerHTML = greeter(user); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Student = /** @class */ (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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html