Ch. 2 · TypeScript

TypeScript Structural Typing and Excess Properties

TypeScript Structural Typing and Excess Properties. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readintermediateupdated Oct 3, 2026

Compatibility primarily follows structure, not declared names. Excess-property checks catch some mistakes in fresh object literals but are not exact-object guarantees.

Before you start

You should be comfortable with JavaScript values, functions and objects. Use a TypeScript project with strict checking enabled when trying the examples. Separate what the compiler proves from what must still be checked when values arrive at runtime.

The practical goal is to reason through this situation: A variable with extra properties can often satisfy a smaller interface if required fields match. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Compare required structure

An interface is satisfied by compatible fields. The object’s declaration name is usually irrelevant to that compatibility decision.

Step 2: Observe fresh-literal checks

A fresh literal can trigger excess-property checking. An existing variable may still be assignable to a smaller shape with extra fields.

Step 3: Enforce external shape at runtime

If unknown properties are forbidden or sensitive, use validation or construct a whitelisted object. Assignment does not strip fields.

Worked scenario

A variable with extra properties can often satisfy a smaller interface if required fields match.

type PublicUser = { name: string };
const internal = { name: 'Ada', token: 'secret' };
const publicView: PublicUser = internal;
console.log(Object.keys(publicView)); // name and token
const sanitized: PublicUser = { name: internal.name };
console.log(Object.keys(sanitized)); // name only
TypeScript

PublicView has a smaller static interface but still points at internal. Sanitized is a new runtime object containing only the intended field, which changes the data actually exposed.

Common mistake

Assignability does not strip extra runtime fields.

Verify the behavior

Compare a fresh object literal assignment with variable assignment. Serialize both views and confirm which fields leave the process; static typing alone is not sanitization.

Interview exercise

Enforce an exact external schema.

Answer and reasoning

Use runtime validation with an explicit unknown-property policy; structural typing is about compatibility, not sanitization.

Continue learning

Compare the scenario with the TypeScript interview questions and test your understanding with the TypeScript MCQs. For terminology and implementation details, consult the reference material.

More in TypeScript

read ✓TypeScript · hard

TypeScript Abstract Classes and Contracts

Share behavior with abstract classes, enforce required members, and decide when an interface or composition is the better contract.

~2 min readread →
read ✓TypeScript · mid

TypeScript Enums vs Union Types

Compare enums with unions of string literals: runtime cost, serialization, exhaustiveness and which one fits application code.

~3 min readread →
esc