Interfaces
An interface names a shape an object should have - a list of property names
and their types, with no runtime code of its own:
interface Product {
name: string;
price: number;
}
Any object with a matching name and price satisfies Product - there's no
class to instantiate, no implements keyword required. Once a parameter is
typed product: Product, you (and your editor) know exactly which properties
are safe to read inside the function.
Your task: define Product with name: string and price: number, then
write describe(product) returning "<name> - $<price>".
You'll practice:
- Declaring an
interface for an object shape
- Typing a function parameter with that interface
Related reading: Objects, Interfaces & Type Aliases - Describing Shapes →