TypeScript's Flexible Type System for Efficient Programming

TypeScript's type system is the one I've enjoyed working with since day one. Not because it's the safest or the most strict. It's neither, actually. `any` breaks every guarantee, the compiler trusts your type assertions blindly, some rules it just doesn't enforce. But it lets me do something I haven't seen elsewhere: take a type, iterate over its keys, remap values, filter by condition, drop fields — all at the type level, before a single line runs. Less annotation, more like a query language for shapes. Most type systems tell you what things are. TypeScript also lets you express how one type becomes another. And it was built on top of JavaScript — a language where any value can be anything at runtime. The type system had to be flexible enough to describe that mess. Turns out, that's what made it powerful. The type system built for the messiest language ended up being the most interesting one to work with. What’s your favorite type-level trick in your language? #TypeScript #Programming #SoftwareEngineering #DeveloperExperience #JavaScript

  • text

Interesting, I would improve that way: type SearchForm< T, Allowed extends unknown = string > = { [K in keyof T as T[K] extends Allowed ? K : never]: FormField<T[K]> } You can have type SearchUser = SearchForm<User, string | number> What do you think ?

I really enjoy working with TypeScript because it really allows you to type check just as much as you want, and gets out of your way as soon as you request it. I've yet to find another language that gets me this power in such a comfortable way...

See more comments

To view or add a comment, sign in

Explore content categories