Skip to content

Commit 1041a55

Browse files
fix(mashups): resolve type errors
Fixes TypeScript check errors in the 'mashups' directory. - Adds JSDoc annotations to resolve implicit 'any' types. - Corrects argument types for API calls. - Defines a local type for the onEdit event object. - Refactors code to avoid variable reassignment with different types.
1 parent 275a497 commit 1041a55

File tree

9 files changed

+28
-14
lines changed

9 files changed

+28
-14
lines changed

mashups/sheets2calendar.gs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function createEventsFromSpreadsheet() {
88
// Open the spreadsheet and get the data.
99
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
1010
var sheet = ss.getSheets()[0];
11+
/** @type {string[][]} */
1112
var data = sheet.getDataRange().getValues();
1213

1314
// Remove any frozen rows from the data, since they contain headers.
@@ -17,10 +18,10 @@ function createEventsFromSpreadsheet() {
1718
data.forEach(function(row) {
1819
var title = row[0];
1920
var description = row[1];
20-
var emails = row[2];
21+
var emailsStr = row[2];
2122

2223
// Split the emails into an array and remove extra whitespace.
23-
emails = emails.split(',').map(function(email) {
24+
var emails = emailsStr.split(',').map(function(email) {
2425
return email.trim();
2526
});
2627

mashups/sheets2chat.gs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @typedef {Object} SheetEditEvent
3+
* @property {string} oldValue The old value of the cell.
4+
* @property {string} value The new value of the cell.
5+
*/
6+
17
/**
28
* Posts a message to a Hangouts Chat room every time the spreadsheet is edited.
39
* This script must be attached to the spreadsheet (created in Google Sheets under
@@ -8,7 +14,7 @@
814
* "From spreadsheet", "On edit".
915
* - Click "Save".
1016
*
11-
* @param {Object} e The onEdit event object.
17+
* @param {SheetEditEvent} e The onEdit event object.
1218
*/
1319
function sendChatMessageOnEdit(e) {
1420
var range = SpreadsheetApp.getActiveRange();

mashups/sheets2docs.gs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function createDocsFromSpreadsheet() {
88
// Open the spreadsheet and get the data.
99
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
1010
var sheet = ss.getSheets()[0];
11+
/** @type {string[][]} */
1112
var data = sheet.getDataRange().getValues();
1213

1314
// Remove any frozen rows from the data, since they contain headers.
@@ -17,10 +18,10 @@ function createDocsFromSpreadsheet() {
1718
data.forEach(function(row) {
1819
var title = row[0];
1920
var content = row[1];
20-
var emails = row[2];
21+
var emailsStr = row[2];
2122

2223
// Split the emails into an array and remove extra whitespace.
23-
emails = emails.split(',').map(function(email) {
24+
var emails = emailsStr.split(',').map(function(email) {
2425
return email.trim();
2526
});
2627

mashups/sheets2drive.gs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function createDriveFilesFromSpreadsheet() {
88
// Open the spreadsheet and get the data.
99
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
1010
var sheet = ss.getSheets()[0];
11+
/** @type {string[][]} */
1112
var data = sheet.getDataRange().getValues();
1213

1314
// Remove any frozen rows from the data, since they contain headers.
@@ -17,10 +18,10 @@ function createDriveFilesFromSpreadsheet() {
1718
data.forEach(function(row) {
1819
var fileName = row[0];
1920
var htmlContent = row[1];
20-
var emails = row[2];
21+
var emailsStr = row[2];
2122

2223
// Split the emails into an array and remove extra whitespace.
23-
emails = emails.split(',').map(function(email) {
24+
var emails = emailsStr.split(',').map(function(email) {
2425
return email.trim();
2526
});
2627

mashups/sheets2forms.gs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function createFormsFromSpreadsheet() {
88
// Open the spreadsheet and get the data.
99
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
1010
var sheet = ss.getSheets()[0];
11+
/** @type {string[][]} */
1112
var data = sheet.getDataRange().getValues();
1213

1314
// Remove any frozen rows from the data, since they contain headers.
@@ -17,10 +18,10 @@ function createFormsFromSpreadsheet() {
1718
data.forEach(function(row) {
1819
var title = row[0];
1920
var question = row[1];
20-
var emails = row[2];
21+
var emailsStr = row[2];
2122

2223
// Split the emails into an array and remove extra whitespace.
23-
emails = emails.split(',').map(function(email) {
24+
var emails = emailsStr.split(',').map(function(email) {
2425
return email.trim();
2526
});
2627

mashups/sheets2gmail.gs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function sendEmailsFromSpreadsheet() {
88
// Open the spreadsheet and get the data.
99
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
1010
var sheet = ss.getSheets()[0];
11+
/** @type {string[][]} */
1112
var data = sheet.getDataRange().getValues();
1213

1314
// Remove any frozen rows from the data, since they contain headers.
@@ -20,7 +21,7 @@ function sendEmailsFromSpreadsheet() {
2021
var emails = row[2];
2122

2223
// Send the email.
23-
GmailApp.sendEmail(emails, subject, null, {
24+
GmailApp.sendEmail(emails, subject, '', {
2425
htmlBody: htmlMessage
2526
});
2627
});

mashups/sheets2maps.gs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ function COUNTY(address) {
1616
if (!results || results.length === 0) {
1717
throw new Error('Unknown address');
1818
}
19-
var counties = results[0].address_components.filter(function(component) {
19+
/** @type {{long_name: string, types: string[]}[]} */
20+
var addressComponents = results[0].address_components;
21+
var counties = addressComponents.filter(function(component) {
2022
return component.types.indexOf('administrative_area_level_2') >= 0;
2123
});
2224
if (!counties.length) {

mashups/sheets2slides.gs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function createPresentationsFromSpreadsheet() {
88
// Open the spreadsheet and get the data.
99
var ss = SpreadsheetApp.openByUrl('ENTER SPREADSHEET URL HERE');
1010
var sheet = ss.getSheets()[0];
11+
/** @type {string[][]} */
1112
var data = sheet.getDataRange().getValues();
1213

1314
// Remove any frozen rows from the data, since they contain headers.
@@ -17,10 +18,10 @@ function createPresentationsFromSpreadsheet() {
1718
data.forEach(function(row) {
1819
var title = row[0];
1920
var content = row[1];
20-
var emails = row[2];
21+
var emailsStr = row[2];
2122

2223
// Split the emails into an array and remove extra whitespace.
23-
emails = emails.split(',').map(function(email) {
24+
var emails = emailsStr.split(',').map(function(email) {
2425
return email.trim();
2526
});
2627

mashups/sheets2translate.gs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function onEdit() {
1212
var range = SpreadsheetApp.getActiveRange();
1313
var value = range.getValue();
1414
if (typeof value === 'string') {
15-
var translated = LanguageApp.translate(value, null, 'en');
15+
var translated = LanguageApp.translate(value, '', 'en');
1616
range.setNote(translated);
1717
}
1818
}

0 commit comments

Comments
 (0)