|
|
|
|
|
by erikpukinskis
1478 days ago
|
|
IMO reusing types is an anti-pattern. It leads to knots of functions which are all tightly coupled since they “use the same types” even though they actually only need small subsets of those types. Changing one of these functions will then often break several of the conjoined functions. When you start to hear people say of their PRs “it works but I just have to fix the types”, that usually means the codebase is trying to re-use too many types. In my experience. The beauty of TypeScript is that you can have two different very narrowly specified types and the compiler will tell you if they’re compatible or not. Reusing types is throwing away the most valuable feature of TypeScript. For me, the type signature is part of the function signature and therefore should not be re-used. Imagine what a disaster it would be if function signatures were reusable: sig UserDatabase(user, db)
create: UserDatabase =>
db.write(“users”, user)
update: UserDatabase =>
db.get(“users”, user.id).update(user)
It’s too much. DRY can be taken too far. |
|