admin管理员组

文章数量:1390707

I'm making a Google Apps Script function that takes two parameters: a Spreadsheet object and a Transaction object, which I created. How can I specify that I want my parameters to have that type?

I'm looking for this functionality:

function addTransaction(Spreadsheet sheet,Transaction t){//blah blah blah doesn't matter}

I'm making a Google Apps Script function that takes two parameters: a Spreadsheet object and a Transaction object, which I created. How can I specify that I want my parameters to have that type?

I'm looking for this functionality:

function addTransaction(Spreadsheet sheet,Transaction t){//blah blah blah doesn't matter}
Share Improve this question edited Mar 26, 2024 at 22:29 VLAZ 29.1k9 gold badges63 silver badges84 bronze badges asked Mar 19, 2021 at 1:47 nikko.guynikko.guy 611 silver badge8 bronze badges 1
  • Wele to Stack Overflow. Please add a brief description of your search efforts as is suggested in How to Ask. Also add more details of the IDE that you are using and if you are open to use another one. – Wicket Commented Mar 19, 2021 at 2:47
Add a ment  | 

2 Answers 2

Reset to default 4

Google Apps Script is based on JavaScript which is not a statically typed language. You can't enforce types. You will need to manually check the types in your function body.

You can use JSDoc syntax to show hints, like this. (not sure what Transaction means, but hope you get the idea)

/**
 * @param {SpreadsheetApp.Spreadsheet} sheet
 * @param {Transaction} t
 */
function addTransaction(sheet, t){ blah blah}

See here or more details: https://jsdoc.app/tags-param

本文标签: javascriptcreate a function with specific parameter typesStack Overflow