|
@@ -1,9 +1,12 @@
|
|
-import {Book, Logger as DamageLogger, Librarian} from './interfaces';
|
|
|
|
|
|
+import {Book, Librarian, Logger as DamageLogger} from './interfaces';
|
|
import {Category} from './enums';
|
|
import {Category} from './enums';
|
|
-import {Journal, ReferenceItem, UniversityLibrarian} from './classes';
|
|
|
|
-import { CalculateLateFees as CalcFee, MaxBooksAllowed } from './lib/utilityfunctions';
|
|
|
|
|
|
+import {ReferenceItem, UniversityLibrarian} from './classes';
|
|
|
|
+import {
|
|
|
|
+ CalculateLateFees as CalcFee,
|
|
|
|
+ MaxBooksAllowed, Purge
|
|
|
|
+} from './lib/utilityfunctions';
|
|
import refBook from './encyclopedia';
|
|
import refBook from './encyclopedia';
|
|
-import { LogAndReturn }from './generics';
|
|
|
|
|
|
+import {Books, LogAndReturn} from './generics';
|
|
|
|
|
|
export function GetAllBooks(): Book[] {
|
|
export function GetAllBooks(): Book[] {
|
|
const books = [
|
|
const books = [
|
|
@@ -209,13 +212,56 @@ function genericFunctionDemo() {
|
|
interface Magazine { title: string }
|
|
interface Magazine { title: string }
|
|
|
|
|
|
let someString: string = LogAndReturn<string>('log this');
|
|
let someString: string = LogAndReturn<string>('log this');
|
|
- console.log("Returned: ", someString);
|
|
|
|
|
|
+ console.log('Returned: ', someString);
|
|
let newMag: Magazine = { title: 'Web dev monthly' };
|
|
let newMag: Magazine = { title: 'Web dev monthly' };
|
|
let someMag: Magazine = LogAndReturn<Magazine>(newMag);
|
|
let someMag: Magazine = LogAndReturn<Magazine>(newMag);
|
|
console.log('Returned mag', someMag);
|
|
console.log('Returned mag', someMag);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+function purgedemo() {
|
|
|
|
+ let inventory: Books = [
|
|
|
|
+ {
|
|
|
|
+ author: 'K & R',
|
|
|
|
+ available: true,
|
|
|
|
+ category: Category.Software,
|
|
|
|
+ id: 10,
|
|
|
|
+ title: 'The C programming language',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ author: 'Steve McConnell',
|
|
|
|
+ available: true,
|
|
|
|
+ category: Category.Software,
|
|
|
|
+ id: 11,
|
|
|
|
+ title: 'Code Complete',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ author: 'A. B.',
|
|
|
|
+ available: true,
|
|
|
|
+ category: Category.Software,
|
|
|
|
+ id: 12,
|
|
|
|
+ title: '8-Bit graphics with Cobol',
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ author: 'C. D.',
|
|
|
|
+ available: true,
|
|
|
|
+ category: Category.Software,
|
|
|
|
+ id: 13,
|
|
|
|
+ title: 'Cool autoexec.bat scripts',
|
|
|
|
+ }
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ // Inventory is accepted because Books is an alias for Array<Book>, so the
|
|
|
|
+ // signature actually matches.
|
|
|
|
+ let purgedBooks: Books = Purge(inventory);
|
|
|
|
+ // Note that purgedBooks uses the aliases type after the assignment.
|
|
|
|
+ purgedBooks.forEach(book => console.log(book.title));
|
|
|
|
+
|
|
|
|
+ let purgedNums: Array<number> = Purge<number>([1, 2, 3, 4]);
|
|
|
|
+ console.log(purgedNums);
|
|
|
|
+}
|
|
|
|
+
|
|
false && bookDemo();
|
|
false && bookDemo();
|
|
false && classDemo();
|
|
false && classDemo();
|
|
false && importDemo();
|
|
false && importDemo();
|
|
-genericFunctionDemo();
|
|
|
|
|
|
+false && genericFunctionDemo();
|
|
|
|
+purgedemo();
|