DomainScoreCursor Rules
GitHub

1/23/2025

Comprehensive guide and rules for developing Google Apps Script projects using TypeScript and Clasp, focusing on best practices, performance optimization, and secure coding.



# TypeScript (Clasp App Script)

# TypeScript Development with Google Apps Script using Clasp

## Overview
This document outlines the best practices and guidelines for developing Google Apps Script projects using TypeScript and Clasp. It covers coding standards, performance optimization, and security measures to ensure efficient and secure script development.

## Coding Standards
- **Functional Programming**: Use functional programming patterns where appropriate. Utilize classes for Google Apps Script services and custom objects.
- **Modularization**: Prefer iteration and modularization over code duplication.
- **Naming Conventions**: Use PascalCase for class names and camelCase for functions and variables. Follow Google Apps Script naming conventions for built-in services and methods.
- **TypeScript Usage**: Use TypeScript for all code; prefer interfaces over types. Use enums for Google Apps Script constants and implement custom types for Google Apps Script objects and return types.
- **Syntax and Formatting**: Use the `function` keyword for global functions and methods. Use arrow functions for callbacks and anonymous functions.

## Performance Optimization
- **API Calls**: Minimize API calls and use batch operations when possible.
- **Caching**: Implement caching strategies for frequently accessed data.
- **Data Structures**: Use efficient data structures and algorithms suitable for script limitations.

## Security Measures
- **Authorization**: Implement proper authorization scopes for Google Services.
- **Error Handling**: Follow Google Apps Script best practices for error handling and logging.
- **Data Handling**: Implement proper security measures for handling user data and authentication.

## Development Tools
- **Clasp**: Use Clasp for version control and deployment of Google Apps Script projects.
- **Documentation**: Follow Google Apps Script documentation for Services, Advanced Services, and Extend Google Workspace.

## Best Practices
- **Triggers**: Use time-based, event-driven, or custom triggers appropriately.
- **Execution Time**: Optimize script execution time and quota usage.
- **Readability**: Focus on readability over performance.

## Conclusion
By adhering to these guidelines, developers can create robust, efficient, and secure Google Apps Script projects using TypeScript and Clasp. Always refer to the latest Google Apps Script documentation and TypeScript best practices to stay updated with new features and improvements.