generics.ts 429 B

12345678910111213141516171819
  1. import {Book} from "./interfaces";
  2. export type Books = Array<Book>;
  3. export function booksTest() {
  4. let poetryBooks: string[] = ['a'];
  5. let fictionBooks: Array<string> = ['b'];
  6. let historyBooks = new Array<Book>(5);
  7. // Forbidden
  8. // let historyBooks: Books = new Books(5);
  9. console.log(poetryBooks, fictionBooks, historyBooks);
  10. }
  11. export function LogAndReturn<T>(thing: T): T {
  12. console.log(thing);
  13. return thing;
  14. }