1 min read

Enforce type declarations

Also related: Clarify function contracts

Type declarations define the shape and behavior of data in code. By providing explicit information about variables and functions, engineers are better equipped to understand the function of a piece of code. Types also enable IDEs to offer intelligent features like auto-completion, error detection, and code navigation. This same "type" information is crucial for AI systems and automated tooling to process, analyze and generate code effectively. Without types, both development tools and AI systems must rely on assumptions, increasing the risk of errors and extending development time.

💡
Clear type declarations serve as crucial documentation for both developers and AI systems, enabling more accurate code analysis, generation, and validation while eliminating guesswork about data types.

Examples

interface User {
  // Core Identity
  id: string;                    // UUID v4
  email: string;                 // Unique, lowercase
  username: string;              // Unique, 3-30 chars
  passwordHash: string;          // Argon2 hash
  
  // Profile Information
  displayName: string;           // 1-50 chars
  avatarUrl?: string;            // URL to CDN
  bio?: string;                  // Max 500 chars
}

interface FindUserParams {
  id?: string;
  email?: string;
  username?: string;
}

type FindUserReturn = Omit;

Recommendation

Apply explicit typing at all levels: variables, function parameters, return types, and class properties. Create custom types that reflect business entities and their constraints. Use union types and interfaces to express complex relationships. Include clear type descriptions that capture domain rules and validation requirements. Leverage type inference where it enhances readability without sacrificing type safety.

Subscribe to our newsletter.

Be the first to know - subscribe today