I knew TypeScript uses structural typing and could explain the basics fine.
Start by clearly defining structural typing (shape-based) and nominal typing (name-based), contrasting their trade-offs in flexibility vs. safety. Then explain how TypeScript's structural type system can be augmented with branded types to emulate nominal typing, and provide a concrete example. Finally, discuss practical implications, especially in safety-critical domains like Boeing.
Pro tip: Emphasize that branded types are a compile-time-only construct with zero runtime overhead, and mention that they can prevent entire classes of bugs by making invalid states unrepresentable—a key principle in safety-critical systems.
Explain that structural typing checks compatibility based on the shape of types (properties and methods), while nominal typing requires explicit declarations or inheritance. Give examples: TypeScript is structural; Java/C# are nominal.
Discuss how structural typing offers flexibility and ease of composition but can lead to unintended type compatibility. Nominal typing provides stronger guarantees and clearer intent but can be more verbose and less flexible.
Explain that branded types use a phantom property (e.g., a unique symbol or a string literal) to create a distinct type that is incompatible with the base type. Show a simple example: `type UserId = string & { __brand: 'UserId' }`.
Show how to create and use branded types: define a constructor function that casts to the branded type, and illustrate that you cannot accidentally pass a plain string where a UserId is expected. Mention that this enforces nominal-like behavior at compile time.
Relate to Boeing's context: in safety-critical systems, preventing mix-ups between semantically different but structurally identical types (e.g., meters vs. feet, or different IDs) is crucial. Branded types help catch such errors at compile time without runtime cost.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.