Reading Note: Nominal type and Structural type


Today I learn that an important attribute of every type system is whether they are structural or nominal.

A static type checker uses either the names or the structure of the types to compare them against other types. Checking against the name is nominal typing and checking against the structure is structural typing.

Nominal Type

In a nominal, or nominative, or name-based type system, two types are deemed to be the same if they have the same name.

Subtyping: type T1 is deemed to be a subtype of a type T2 if T1 is explicitly declared to be a subtype of T2.


class Person {
    public name: string;

class Employee extends Person {
    public salary: number;

class Manager extends Employee { }

class Product {
    public name: string;
    public price: number;

Structural Type

In a structural type system, two types are deemed the same if they are of the same structure. Two types are the same in structure if they have the same public fields and methods of compatible type/signature.

Subtyping: Type T1 is deemed a subtype of a type T2 if and only if T1 has all public members (of compatible type/signature) that T2 has (but may have more than T2).

Let’s look at the previous code.