Created
March 22, 2020 23:28
-
-
Save PranavBhatia/0789c5379ff67a00324f4fcb93996b96 to your computer and use it in GitHub Desktop.
This file contains 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
// Interface can also be called a contract. | |
// We can use them to define custom types without creating classes. | |
// Interfaces ARE NOT compiled to JavaScript! It's just for checking/validation done by our TypeScript compiler. | |
// Employee interface | |
interface Employee { | |
employeeName: string; | |
salary: number; | |
mobileNumber?: string; // Optional property => Does not have to be implemented | |
} | |
let employee: Employee; | |
// This value does not satisfy the interface => Compilation error | |
// user = { anything: 'anything', anynumber: 5}; | |
// This value does satisfy the interface | |
employee = {employeeName: 'John', salary: 1234}; | |
console.log(employee); | |
// Result => { employeeName: 'John', salary: 1234 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment