3 ms·
This shows how complex TypeSript has become. It may be fun to write complicated Type annotations such as this, but imagine having to read and maintain the code!
by flowerlad 6y ago
This shows how complex TypeSript has become. It may be fun to write complicated Type annotations such as this, but imagine having to read and maintain the code!
- smt88 6y agoFrom years of real-world experience, it's rare to run into types that are too complex to easily understand. The syntax is pretty easy to read, and the compiler and language service make it easy to navigate types, even if you haven't looked at the source for them yet.
- alangpierce 6y agoFWIW I find that TypeScript types can sometimes be overwhelming or hard to decipher, especially some third-party library type definitions. The connect function from react-redux is one example: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d07d3eefaa7647833dd1446808a8eccd018f3ec9/types/react-redux/v6/index.d.ts#L153 https://github.com/DefinitelyTyped/DefinitelyTyped/blob/d07d... Since types can get really complex, I feel a need to be conscious of avoiding complexity when writing types myself, unless the value is enough to justify a hard-to-read type.
- freeqaz 6y agoThis is the complexity introduced when applying static types to a vanilla JS codebase, imo. It's easy to get crazy with types in vanilla JS. Adding Typescript forces you to resolve the different types explicitly and it can get hairy. What this really demonstrates to me is the difference between starting with TS vs migrating to it. Code that has to think about the types the first time it is being built is going to be better structured, on average, than purely dynamic code.
- eyelidlessness 6y agoMany complex/difficult to understand TS types exist precisely because the type system was too limited to express certain real world use cases without workarounds. As the type system takes on that complexity, and removes more limitations, it actually makes writing simpler types for those cases much easier.
- searchableguy 6y agoFrom ts conf talks, only a minority of people actually write most of the complex types. Those are mainly library authors and such, I presume. https://youtu.be/jmPZztKIFf4 https://youtu.be/jmPZztKIFf4 at 49:50.
- bhandziuk 6y agoI find these types still exist in JS it's just impossible to decipher what you're writing and supposed to be doing without a solid TypeSystem. The types might look complicated but really this is much more simplified that getting runtime errors.