Typescript Helper Types
gist.github.com/ClickerMonkey/a081b990b9b1421...Posted Dec 11, 2020, 11:55 PM UTC
Posted Dec 11, 2020, 11:55 PM UTC
Wondering when you'd use Simplify<T>
What's the case for it?
It's hard to show a simple use case for, but when you start using several types within types and you hover over it it's completely unreadable. So you can wrap the types with simplify and now your type is readable! You may loose some useful nested type information, but sometimes you want to.
May I recommend opening a PR in type-fest?
I’ve been using TypeScript for 3 years and never needed anything like this. I think it obfuscates your code to make utility types you reuse around your codebase. Definitely not a pattern I would recommend.
I develop a lot of libraries with complicated type work (for example, a fully type safe query builder with full SQL support) and it's impossible without these types which can analyze what the user is passing your functions to transform your type or return an intelligent type that matches the user's value.
Most users of TS never need to do this stuff, but these are essential when you're creating a complicated library or creating types for a JS library.
Fair enough!
These are helpful when writing utility methods that work on different types. Using these in main logic only complicates things.
I think it would be work making a PR for utility-types with the ones you have here that they don't already have.
Actually, type-fest seems to be the big types lib.
This is a phenomenal list! As another library maker I've made a few of these along the way, nice to have them all in one spot though. Ts-toolbelt is another great reference for complicated types as well.
I especially like Simplify. It's nice to unravel a deeply complex type into something reasonable.
Thanks! I don't know why I thought Simplify would actually do anything, but it does and definitely makes a difference in usability.