Skip to catalogue

257

structural typing

also duck typing, TypeScript excess property check

TypeScript checks the shape, not the name. A type assertion throws that check away.

What is structural typing?

Structural typing means two types are compatible when their fields match. A name does not make them different. Excess property checks apply to fresh object literals, not to a variable you already typed. `as` and a non-null assertion silence the compiler. They do not check anything at runtime.

Why does structural typing matter when vibe coding?

The draft adds `as User` so the error goes away, or it types a response as any. The field was renamed. The screen reads undefined and the compiler is quiet.

How do you do structural typing?

Parse at the boundary with a schema. Let inference work. Use a type assertion only where you just proved the fact. Prefer a narrower type over any.

How do you ask a model for structural typing?

Type (value) without `as` and without any. If it comes from JSON, parse it with a schema. Do not assert it is (type). Excess fields on an object literal should be an error.

What goes wrong with structural typing?

Optional fields everywhere so the assignment succeeds. You moved the crash to the line that reads the field.

adjacent