Interfaces can contain method signatures as well. These won't contain the implementation of the method; they define the contracts for when interfaces are used in an implementation.
Let's look at an example:
- Let's add a method to the OrderDetail interface we just created. Our method is called getTotal and it has a discount parameter of type number and returns a number:
interface OrderDetail { product: Product; quantity: number; getTotal(discount: number): number; }
Notice that the getTotal method on the interface doesn't specify anything about how the total is calculated – it just specifies the method signature that should be used.
- Having adjusted our OrderDetail interface, our tableOrder object, which implemented this ...