diff --git a/types/google.script.client-side/google.script.client-side-tests.ts b/types/google.script.client-side/google.script.client-side-tests.ts index 5e3c059c01..57867f8456 100644 --- a/types/google.script.client-side/google.script.client-side-tests.ts +++ b/types/google.script.client-side/google.script.client-side-tests.ts @@ -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 } + location.hash; // $ExpectType string + location.parameter; // $ExpectType { [key: string]: string; } + location.parameters; // $ExpectType { [key: string]: ReadonlyArray; } }); 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 } + e.state; // $ExpectType State + e.location.hash; // $ExpectType string + e.location.parameter; // $ExpectType { [key: string]: string; } + e.location.parameters; // $ExpectType { [key: string]: ReadonlyArray; } }); 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 diff --git a/types/google.script.client-side/index.d.ts b/types/google.script.client-side/index.d.ts index 7d497fd6c2..23e92255a7 100644 --- a/types/google.script.client-side/index.d.ts +++ b/types/google.script.client-side/index.d.ts @@ -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 // 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; - } + }; } diff --git a/types/google.script.client-side/tsconfig.json b/types/google.script.client-side/tsconfig.json index 83c99e2f06..e573df04f9 100644 --- a/types/google.script.client-side/tsconfig.json +++ b/types/google.script.client-side/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "dom" ], "noImplicitAny": true, "noImplicitThis": true,