Interface basics
An interface describes the shape of an object — the property names and their types — without saying anything about where the object came from. TypeScript uses structural typing (sometimes called duck typing): any object with the right properties satisfies the interface, whether or not it was ever declared with that interface in mind. This is different from languages like Java or C#, where a class has to explicitly say it implements an interface.
You should see
Ada is 36
Grace is 40email: string property to the User interface, then fix ada so it still satisfies the type.TS2741: a required property is missing
interface User {
name: string
age: number
}
const bad: User = { name: "Ada" }app.ts:6:7 - error TS2741: Property 'age' is missing in type '{ name: string; }' but required in type 'User'.
6 const bad: User = { name: "Ada" }
~~~Structural typing checks that an object has every property the interface requires, with a compatible type for each one. bad is missing age entirely, so its shape does not match User.
Add the missing property.
const bad: User = { name: "Ada", age: 36 }- Structural typing
- A type system that checks compatibility by comparing shape (property names and types) rather than by name or explicit declaration.
- Duck typing
- "If it walks like a duck and quacks like a duck…" — the informal name for structural typing: an object qualifies by having the right members, not by declaring an identity.
