TypeScript Concepts

Structural typing — shape-based compatibility

Compatibility usually depends on members rather than declared names. A value with additional members can satisfy a narrower contract without inheritance. Fresh object literals receive additional checks, and private/protected members and some other constructs introduce identity-related restrictions. Observed output: '8'. Local example verified with TypeScript 5.8.3, strict checking, ES2022/CommonJS and Node.js 22.16.0; declarations enabled.

Formal Syntax & Structure

typescript syntaxtypescript
type Shape = { id: number };

Working Example

Example Snippettypescript
type Identified = { id: number };const order = { id: 8, total: 12 };const item: Identified = order;console.log(item.id);
TypeScript Reference