Object Shapes
Object Shapes
π¨βπΌ Let's create interfaces for our domain objects. Interfaces are the standard
way to define object shapes in TypeScript.
π¨ Open
and:
- Create a
Productinterface with:id: string,name: string,price: numberstatus: 'active' | 'inactive' | 'discontinued'- optional
description?: string
- Implement
getProductSummary(product: Product): stringthat includes the name, price, and either the description or a clear no-description fallback (intended shape: name, price, then description text) - Create
product(no description) andproductWithDesc(withdescription: 'Has description') sample values - Export
getProductSummary,product, andproductWithDescby name
Completion criteria
- Named exports:
getProductSummary,product,productWithDesc - Both samples use a valid
statusunion member product.descriptionisundefined;productWithDesc.descriptionis'Has description'- Summary includes name and price, and uses the description when present (otherwise a no-description fallback) so the two samples produce different strings