Merge pull request #33549 from clomie/google-script-client-side

[google.script.client-side] Improve type of google.script.run object
This commit is contained in:
Nathan Shively-Sanders
2019-03-04 10:42:24 -08:00
committed by GitHub
3 changed files with 86 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
google.script.url.getLocation(location => {
location.hash; // $ExpectedType string
location.parameter; // $ExpectedType { [key: string]: string }
location.parameters; // $ExpectedType { [key: string]: ReadonlyArray<string> }
location.hash; // $ExpectType string
location.parameter; // $ExpectType { [key: string]: string; }
location.parameters; // $ExpectType { [key: string]: ReadonlyArray<string>; }
});
google.script.history.push(null);
@@ -13,10 +13,10 @@ google.script.history.replace({ timestamp: Date.now() }, { foo: 'bar', fiz: 'baz
google.script.history.replace({ timestamp: Date.now() }, { foo: ['bar', 'cat'], fiz: 'baz' }, 'anchor1');
google.script.history.setChangeHandler(e => {
e.state; // $ExpectedType google.script.history.State
e.location.hash; // $ExpectedType string
e.location.parameter; // $ExpectedType { [key: string]: string }
e.location.parameters; // $ExpectedType { [key: string]: ReadonlyArray<string> }
e.state; // $ExpectType State
e.location.hash; // $ExpectType string
e.location.parameter; // $ExpectType { [key: string]: string; }
e.location.parameters; // $ExpectType { [key: string]: ReadonlyArray<string>; }
});
google.script.host.origin; // $ExpectType string
@@ -25,15 +25,79 @@ google.script.host.editor.focus();
google.script.host.setHeight(450);
google.script.host.setWidth(300);
google.script.run.withSuccessHandler(() => {}).executeScript({ message: 'test for google.script.run' });
google.script.run.withSuccessHandler(() => {}); // $ExpectType Runner
google.script.run.withFailureHandler(() => {}); // $ExpectType Runner
google.script.run.withUserObject({}); // $ExpectType Runner
google.script.run
.withSuccessHandler(value => {})
.withFailureHandler(error => {})
.getEmail();
.withFailureHandler(error => {
error; // $ExpectType Error
});
google.script.run
.withSuccessHandler((value, userObject) => {})
.withFailureHandler((error, userObject) => {})
.withUserObject({})
.getSomeData(Date.now(), { options: 'none' }, 'anchor1', true, null);
.withFailureHandler((error, userObject) => {
error; // $ExpectType Error
})
.withUserObject({});
google.script.run.testFunctionWithoutParameter();
google.script.run.testFunctionWithNumber(0);
google.script.run.testFunctionWithBoolean(true);
google.script.run.testFunctionWithString("");
google.script.run.testFunctionWithNull(null);
google.script.run.testFunctionWithArray([
0,
true,
"",
null,
undefined,
[],
{
number: 0,
boolean: true,
string: "",
nullValue: null,
undef: undefined,
array: [0, true, "", null, undefined, [], {}],
object: {}
}
]);
google.script.run.testFunctionWithObject({
number: 0,
boolean: true,
string: "",
nullValue: null,
undef: undefined,
array: [0, true, "", null, undefined, [], {}],
object: {}
});
google.script.run.testFunctionWithMultipleParameters(
0,
true,
"",
null,
undefined,
[
0,
true,
"",
null,
undefined,
[],
{}
],
{
number: 0,
boolean: true,
string: "",
nullValue: null,
undef: undefined,
array: [0, true, "", null, undefined, [], {}],
object: {}
}
);
google.script.run.testFunctionWithForm(new HTMLFormElement());
google.script.run.testFunctionWithDateError(new Date()); // $ExpectError
google.script.run.testFunctionWithFunctionError(() => {}); // $ExpectError

View File

@@ -1,4 +1,4 @@
// Type definitions for non-npm package Google Apps Script Client-side API 0.0
// Type definitions for non-npm package Google Apps Script Client-side API 0.1
// Project: https://developers.google.com/apps-script/guides/html/reference/host
// Definitions by: clomie <https://github.com/clomie>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -118,12 +118,14 @@ declare namespace google.script {
const run: Runner;
interface Runner {
type Parameter = number | boolean | string | { [index: number]: Parameter } | { [key: string]: Parameter } | null | undefined;
type Runner = {
/**
* Executes the server-side Apps Script function with the corresponding name.
*/
[functionName: string]: (...args: any[]) => void;
[functionName: string]: (first?: Parameter | HTMLFormElement, ...rest: Parameter[]) => void;
} & {
/**
* Sets a callback function to run if the server-side function throws an exception.
* Without a failure handler, failures are logged to the JavaScript console.
@@ -147,5 +149,5 @@ declare namespace google.script {
* User objects cannot, however, be objects constructed with the new operator
*/
withUserObject(object: any): Runner;
}
};
}

View File

@@ -2,7 +2,8 @@
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,