// Aliase and interface allows types to be easily shared between different variables/objects.
//Example 1=================================
interface Products {
name: string;
brand: string;
quantity: number;
price: number;
}
const products: Products = {
name: 'Laptop',
brand: 'Dell',
quantity: 12,
price: 14000,
};
const calculateProductPrice = (product: Products): number => {
const { quantity, price } = product;
return quantity * price;
};
console.log(calculateProductPrice(products));
//Example2=================================
interface Rectangle {
height: number;
width: number;
}
const rectangle: Rectangle = {
height: 20,
width: 10,
};
interface ColoredRectangle extends Rectangle {
color: string;
}
const coloredRectangle: ColoredRectangle = {
height: 20,
width: 10,
color: 'red',
};
//* *************************
//* Type VS Interface
//?1 ===============================
//* Use custom types when you need unions, intersection, or mapped types
//* Use interfaces when defning object shapes or classes that
//?2 ================================
//* Interfaces can extends other interfcas to inherit their properties.
//* Custom types can use unios and interfcas for more complex type compositionss
//* *************************