Skip to content

Structural Typing

In one line

Structural typing is a type system where compatibility is determined by the structure (properties) of types, not by their names or declarations.

In simple words

Structural typing means "if it looks like a duck and quacks like a duck, it's a duck." TypeScript checks the shape of a type — its properties and their types — to determine compatibility, not the type's name.

This is different from nominal typing (used in Java, C#) where types are only compatible if they have an explicit inheritance relationship. In TypeScript, any object with the right properties is compatible, even if it was never declared as the target type.

Structural typing makes TypeScript flexible and JavaScript-like, but it can lead to surprising compatibilities. It is a core design principle of the language.

Example

typescript
interface Point { x: number; y: number; }

// No explicit relationship to Point
const coord = { x: 10, y: 20, label: "origin" };

const p: Point = coord; // OK: coord has x and y

coord is compatible with Point because it has x and y properties, despite no declared relationship.

Related terms

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary