Software design and clean code

Stage 1 · Lesson 8 of 8

TypeScript: classes, interfaces and structural types

Object-oriented programming properly

TypeScript types are structural: any object with the right shape fits an , whether or not it says implements. Interfaces and types disappear when the code runs, so you cannot check them at run time; use a , a kind field shared by every variant, when you need to tell types apart.

Classes still exist at run time. The private keyword is only checked by the compiler, while #field is private at run time too. Much TypeScript code prefers plain functions and object literals to classes, and that is fine: the design ideas in this roadmap apply to modules and functions just as much.

Common trapexpecting instanceof to work on an interface, or building deep class hierarchies where a union type and a few functions would read better.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

  • Free exercises in your language with optional human mentoring on design, not just on passing tests

Keep handy

Also worth your time

Mark this stage as not done?