Table of contents
No headings in the article.
Throughout my experience as a developer, I've found that many dev teams have a common custom of naming interfaces with keywords like "type" or "I" when trying to describe TypeScript interfaces.
In this post, we'll explore where this trend comes from and the reasons why I think in TypeScript interfaces it is important to stop this trend of prefixes and suffixes. If you understand the problems and limitations of these conventions, you will have enough understanding to write clear, transparent, and standard code.
Let’s embrace the simplest and easiest way to work with interfaces in TypeScript!
Breaking Free from .NET Habits
This is a convention in the .NET framework, derived from COM/COM+, that is widely used outside of .NET unless it is intentionally added. This convention heavily influenced the early TypeScript, although this focus has been greatly reduced over some time. (For example, IList, IEnumerable, etc, has strong .Net vibes)
Follow TypeScript Community Standards:
The TypeScript network usually follows a naming conference without excessive prefixes or suffixes for interfaces. By adhering to community standards(TypeScript Handbook), you ensure that your code is greater approachable and acquainted with other developers.
Improving code refactoring:
Communicating with a prefix or suffix makes it more difficult to refactor your code later. Renaming interfaces would require updating all references, which could lead to errors and inconsistencies. By using logical interface names without unnecessary prefixes and suffixes, you make less error-prone.
Ensure consistency in the codebase:
Another important reason to avoid prefixes and suffixes in TypeScript interfaces is to maintain consistency across the codebase If multiple developers work on a project, there is a chance that interfaces may be created with the same name but with different prefixes or suffixes, such as "ICar" and "Car" or "CarType". This discrepancy can confuse and complicate the understanding and passing rules.
In summary, by moving away from the legacy .NET convention of excessive prefix suffixing in TypeScript interfaces, you empower yourself and your team to write clean, readable code so well that is industry-standard that it encourages collaboration and future scalability 🚀.