Skip to main content
Okay — now let’s look at types and interfaces in TypeScript. Elmer’s objects are getting more complex, so we need a way to describe their shape. In TypeScript you can declare a type that specifies the properties an object must have. Below is a Duck type with an optional property:
When you write 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.
If you mistype a property name, TypeScript will report a compile-time error. For example, using the British spelling colour will trigger an error:
TypeScript error (cleaned):
Similarly, adding an unknown property that isn’t declared on the type is an error:
You can still add optional properties later by mutating the object referenced by a 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.
Another common way to describe object shapes in TypeScript is an interface. For many basic use cases, type aliases and interface declarations are interchangeable. Here is the same shape expressed both ways:
Both 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.

Quick comparison

Watch Video