A recipe for creating a TypeScript codebase that’s hard to maintain:...
A recipe for creating a TypeScript codebase that’s hard to maintain:
Centralize all types
Downsides:
🚫 We have to constantly jump between files
🚫 It's hard to tell if it's local or global, so we have to find all references to figure out where it's used before we can safely change it.
🚫 It's harder to find reusable types when they're mixed with single use types
Solution:
1. Keep types as local as possible. If it’s for one file, declare the type in that file. Don’t export it.
2. If it’s a reusable type, keep it as local as possible, such as in a feature folder.
3. Used app-wide? Then go ahead and centralize.