Skip to content

Commit a903bd5

Browse files
committed
docs: add TypeScript, Advanced Services, optional property, and error handling best practices; refactor check-gs script argument parsing.
1 parent 003da5d commit a903bd5

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

.github/scripts/check-gs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ async function checkProject(project: Project, rootDir: string): Promise<CheckRes
180180
async function main() {
181181
try {
182182
const rootDir = resolve('.');
183-
const searchArg = process.argv[2];
183+
const args = process.argv.slice(2);
184+
const searchArg = args.find(arg => arg !== '--');
184185

185186
// 1. Discovery
186187
const projectRoots = findProjectRoots(rootDir);

GEMINI.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,35 @@ function find(id) { ... }
282282

283283
### Common Issues & Fixes
284284

285+
- **TypeScript**: DO NOT REFERENCE GoogleAppsScript in JSDocs. Instead use a locally defined type definition and link to the appropriate reference documenation page if possible.
285286
- **"Property 'x' does not exist on type 'Object'"**: This usually means you are accessing a property on a generic object. Define a `@typedef` for that object structure.
286287
- **Implicit 'any'**: If you see "Parameter 'x' implicitly has an 'any' type", it means you forgot a JSDoc `@param` tag. Add it to fix the error.
287-
- **Advanced Services**: To fix errors with these globals, add a simple check and throw an error telling the developer to add the appropriate service. An example is below. Prefer this check at the global scope if used multiple times.
288+
- **Advanced Services**: To fix errors with these globals, check for existence. This helps TypeScript narrow the type and prevents runtime errors if the service is not enabled.
288289

289290
```js
290291
if (!AdminDirectory) {
291-
throw new Error('Enable the AdminDirectory Advanced Service.');
292+
console.log('AdminDirectory Advanced Service must be enabled.');
293+
return;
292294
}
295+
```
296+
297+
- **Optional Properties**: Use optional chaining (`?.`) when accessing properties that might be undefined in API responses. This is often the case when when using `fields` to limit the response.
298+
299+
```js
300+
// Safe access
301+
console.log(user.name?.fullName);
302+
```
303+
304+
- **Error Handling**: Avoid wrapping code in `try/catch` blocks if you are only logging the error message. Let the runtime handle the error reporting for cleaner sample code.
305+
306+
```js
307+
// Avoid this
308+
try {
309+
AdminDirectory.Users.list();
310+
} catch (err) {
311+
console.log(err.message);
312+
}
313+
314+
// Prefer this
315+
AdminDirectory.Users.list();
293316
```

0 commit comments

Comments
 (0)