Use Narrow Types

// ❌ The type used for 'role' is too broad type User { role: string; } // ✅ Using a union type narrows the possible values // The code is now more understandable, and your editor // will be able to provide improved auto-completion. type User { role: 'editor' | 'viewer' | 'admin'; }
Animated image that shows how auto-complete works with narrow types.
Copyright ©2024 Bestpractices.tech. All rights reserved.