TypeScript Interface
Interface
"use strict";
interface Book {
id: number;
title: string;
printBook : () => void
}
class MyBook implements Book{
id : number = 1;
title: string = "MyBook";
printBook(){
console.log(`This is ${this.title}.`);
}
}
let myBook: Book = new MyBook();
myBook.printBook();
function type interface
"use strict";
interface printBookHanlder {
(name: string): void
}
let printOutMyBook = (name: string) => {
console.log(`Your book: ${name}`);
}
printOutMyBook("Harry Potter");