Domain Types
Let’s look at how to suggest improvements for domain types in code reviews. We’ll show you a simple example and explain why the feedback matters.
The Scenario
A developer has written code to handle user data. The code works but could benefit from more specific types.
createUser.ts
// Before
function createUser(data: any) {
return {
name: data.name,
age: data.age,
email: data.email,
}
}PR Comment
Choose the comment that you think is the most constructive and helpful.
Click here to learn more
Improvements
1. Type Safety
- Catches errors at compile time
- Prevents runtime type issues
- Better IDE support
2. Code Quality
- More maintainable code
- Better documentation
- Clearer expectations
3. Developer Experience
- Better autocomplete
- Easier refactoring
- Clearer interfaces
Tips
1. Start Positive
- Acknowledge the working code
- Show you understand the current approach
- Example: “Great work on the user creation!“
2. Explain the Benefits
- Why do types matter?
- How do they help?
- Example: “This improves type safety”
3. Be Specific
- Suggest concrete improvements
- Explain why they matter
- Example: “Adding a proper User interface helps catch errors early”
4. Keep It Friendly
- Focus on improvement, not criticism
- Use encouraging language
- Example: “Thanks for considering type safety!”
Common Pitfalls to Avoid
1. Being Too Critical
- ❌ “This needs proper types.”
- ✅ “Good work! Here’s how we can make it even more type-safe.”
2. Not Explaining Why
- ❌ “Add an interface.”
- ✅ “Adding an interface helps catch errors early.”
3. Ignoring the Positive
- ❌ “This needs type definitions.”
- ✅ “Great work! Here’s how we can make it even more maintainable.”
Remember: The goal is to help your teammate write better code while maintaining a positive and collaborative environment!
Last updated on