Typing objects
Typing objects is just as simple as typing primitive values:
Properties of an object can be marked as optional with the ?
.
Combining object types
Those types have common fields: _id
, price
, and category
.
Let's create a separate type for the common properties and rewrite the types:
Interfaces
Interfaces are another way of creating custom types.
There are some very minor differences between type aliases
and interfaces
. In general interfaces
seem to be more suitable for object-oriented code with classes.
Resources
Last updated
Was this helpful?