Follow consistent naming conventions in TypeScript to improve code clarity, type safety, and developer experience:

  1. Capitalize types and interfaces: All type and interface names should start with an uppercase letter.
    // Incorrect
    type chainTypeName = "stuff" | "map_reduce";
       
    // Correct
    type ChainTypeName = "stuff" | "map_reduce";
    
  2. Use unknown instead of any: When the type is truly not known, prefer unknown over any for better type safety.
    // Incorrect - too permissive
    function isBuiltinTool(tool: any)
       
    // Correct - safer typing
    function isBuiltinTool(tool: unknown)
    
  3. Prefer type literals over strings for constrained values to improve developer experience and catch errors at compile time.
    // Incorrect
    function createLoader(mode: string)
       
    // Correct
    type SearchMode = "subreddit" | "username";
    function createLoader(mode: SearchMode)
    
  4. Use visibility modifiers instead of naming conventions for private/protected members:
    // Incorrect
    class GraphQLClientTool {
      _endpoint: string;
    }
       
    // Correct
    class GraphQLClientTool {
      private endpoint: string;
    }
    
  5. Standardize parameter naming across similar components (e.g., use model instead of modelName for consistency):
    // Standardized
    interface EmbeddingsParams {
      model: string;  // Not modelName
    }
    
  6. Improve type precision when appropriate to enhance developer experience:
    // Less precise
    loaders: { [extension: string]: (path: string) => Loader }
       
    // More precise
    loaders: { [extension: `.${string}`]: (path: string) => Loader }