Browse Source

6.10: extending interfaces.

Frederic G. MARAND 5 years ago
parent
commit
5a80cfc830
2 changed files with 31 additions and 3 deletions
  1. 15 3
      app/app.ts
  2. 16 0
      app/interfaces.ts

+ 15 - 3
app/app.ts

@@ -1,4 +1,4 @@
-import {Book, DamageLogger} from './interfaces';
+import {Author, Book, DamageLogger, Librarian} from './interfaces';
 import {Category} from "./enums";
 
 function GetAllBooks(): Book[] {
@@ -156,5 +156,17 @@ let myBook: Book = {
 // PrintBook(myBook);
 // myBook.markDamaged('Torn back cover');
 
-let logDamage: DamageLogger = reason => console.log(`Damage reported: ${reason}.`);
-logDamage('Coffee stains');
+// let logDamage: DamageLogger = reason => console.log(`Damage reported: ${reason}.`);
+// logDamage('Coffee stains');
+
+let favoriteAuthor: Author = {
+  email: 'foo@example.com',
+  numBooksPublished: 1,
+  name: 'Foo',
+};
+let favoriteLibrarian: Librarian = {
+  email: "jane@example.com",
+  name: 'Jane Doe',
+  departement: 'Sales',
+  assistCustomer: (custName: string) => console.log(`Helping ${custName}.'), 
+}

+ 16 - 0
app/interfaces.ts

@@ -15,7 +15,23 @@ interface Book {
   markDamaged?: DamageLogger,
 }
 
+interface Person {
+  name: string;
+  email: string;
+}
+
+interface Author extends Person {
+  numBooksPublished: number;
+}
+
+interface Librarian extends Person {
+  departement: string;
+  assistCustomer: (custName: string) => void,
+}
+
 export {
+  Author,
   Book,
   DamageLogger,
+  Librarian,
 }