Duck type with an optional property:
const daffy: Duck = ..., your editor will provide IntelliSense for the required properties: name, age, type, and color. The favoriteFood property is optional because of the ?.
The
? after a property name marks it optional — the object may include it or omit it. This helps model real-world objects that may not always have every property.colour will trigger an error:
const. Mutating properties is allowed; reassigning the const variable itself is not.
You can mutate properties on an object declared with
const, but you cannot reassign the const variable itself. This distinction prevents reassignment while allowing object mutation.interface. For many basic use cases, type aliases and interface declarations are interchangeable. Here is the same shape expressed both ways:
DuckType and DuckInterface describe the same required and optional properties. There are advanced differences (for example, declaration merging and some utility-type behaviors) — those are out of scope for this overview.