TypeScript vs JavaScript: Designing with Types

TypeScript is not just "JavaScript with types". The more I use it, the more I feel types are design notes that the compiler can actually check. A bad type usually means one of three things: - I do not understand the data yet - The API contract is weak - I am mixing too many responsibilities in one place Today I refactored a response type from a loose object into a clear union: success response error response validation response The code immediately became easier to read. Good TypeScript is not about writing complex generics everywhere. It is about making impossible states harder to represent. That is the kind of code clients and teams can trust. #TypeScript #JavaScript #CleanCode

To view or add a comment, sign in

Explore content categories