Member-only story
TypeScript is Cumbersome and I Don’t Want to Use It!
Preface
Recently, when our department was working on a component library, I noticed that some team members expressed resistance to using TypeScript, often complaining, “TypeScript is too cumbersome, we don’t want to use it!”At first, I was confused by this: Is TypeScript really that troublesome? However, when I took the time to review the team’s code, I finally figured out what the problem was. In this article, I would like to share with you some of my findings and solutions
1. The type reuse is insufficient
During the code review process, I found a lot of duplicate type definitions, which significantly reduced the reusability of the code.
After further conversation, I learned that many team members were not clear about how to reuse types in TypeScript. TypeScript allows us to define types using type and interface.
When I asked them about the difference between type and interface, most of them said they didn’t know, so it’s no wonder they didn’t know how to reuse types effectively.
Types defined by type can be reused by intersecting types (&), while types defined by interface can be reused by inheritance (extends). It’s important to note that types defined by type and interface can also be reused with each…