@google/clasp 2.5.0 → 3.0.1-alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +251 -196
- package/build/src/auth/auth.js +176 -0
- package/build/src/auth/auth_code_flow.js +36 -0
- package/build/src/auth/credential_store.js +1 -0
- package/build/src/auth/file_credential_store.js +82 -0
- package/build/src/auth/localhost_auth_code_flow.js +63 -0
- package/build/src/auth/serverless_auth_code_flow.js +32 -0
- package/build/src/commands/clone-script.js +71 -0
- package/build/src/commands/create-deployment.js +33 -0
- package/build/src/commands/create-script.js +75 -0
- package/build/src/commands/create-version.js +31 -0
- package/build/src/commands/delete-deployment.js +71 -0
- package/build/src/commands/disable-api.js +19 -0
- package/build/src/commands/enable-api.js +31 -0
- package/build/src/commands/list-apis.js +23 -0
- package/build/src/commands/list-deployments.js +30 -0
- package/build/src/commands/list-scripts.js +28 -0
- package/build/src/commands/list-versions.js +29 -0
- package/build/src/commands/login.js +53 -54
- package/build/src/commands/logout.js +15 -15
- package/build/src/commands/open-apis.js +11 -0
- package/build/src/commands/open-container.js +15 -0
- package/build/src/commands/open-credentials.js +11 -0
- package/build/src/commands/open-logs.js +11 -0
- package/build/src/commands/open-script.js +18 -0
- package/build/src/commands/open-webapp.js +56 -0
- package/build/src/commands/program.js +108 -0
- package/build/src/commands/pull.js +19 -18
- package/build/src/commands/push.js +64 -74
- package/build/src/commands/run-function.js +61 -0
- package/build/src/commands/setup-logs.js +12 -0
- package/build/src/commands/show-authorized-user.js +18 -0
- package/build/src/commands/show-file-status.js +34 -0
- package/build/src/commands/tail-logs.js +92 -0
- package/build/src/commands/utils.js +82 -0
- package/build/src/constants.js +0 -3
- package/build/src/{apis.js → core/apis.js} +90 -92
- package/build/src/core/clasp.js +171 -0
- package/build/src/core/files.js +359 -0
- package/build/src/core/functions.js +51 -0
- package/build/src/core/logs.js +41 -0
- package/build/src/core/manifest.js +1 -0
- package/build/src/core/project.js +313 -0
- package/build/src/core/services.js +179 -0
- package/build/src/core/utils.js +121 -0
- package/build/src/index.js +16 -355
- package/build/src/intl.js +34 -0
- package/docs/README.md +0 -5
- package/docs/config-files.md +0 -1
- package/docs/run.md +2 -2
- package/package.json +86 -51
- package/CHANGELOG.md +0 -79
- package/build/src/apis.d.ts +0 -34
- package/build/src/apis.js.map +0 -1
- package/build/src/apiutils.d.ts +0 -16
- package/build/src/apiutils.js +0 -81
- package/build/src/apiutils.js.map +0 -1
- package/build/src/auth.d.ts +0 -37
- package/build/src/auth.js +0 -310
- package/build/src/auth.js.map +0 -1
- package/build/src/clasp-error.d.ts +0 -3
- package/build/src/clasp-error.js +0 -10
- package/build/src/clasp-error.js.map +0 -1
- package/build/src/commands/apis.d.ts +0 -10
- package/build/src/commands/apis.js +0 -90
- package/build/src/commands/apis.js.map +0 -1
- package/build/src/commands/clone.d.ts +0 -13
- package/build/src/commands/clone.js +0 -60
- package/build/src/commands/clone.js.map +0 -1
- package/build/src/commands/create.d.ts +0 -16
- package/build/src/commands/create.js +0 -81
- package/build/src/commands/create.js.map +0 -1
- package/build/src/commands/default.d.ts +0 -8
- package/build/src/commands/default.js +0 -10
- package/build/src/commands/default.js.map +0 -1
- package/build/src/commands/deploy.d.ts +0 -13
- package/build/src/commands/deploy.js +0 -51
- package/build/src/commands/deploy.js.map +0 -1
- package/build/src/commands/deployments.d.ts +0 -5
- package/build/src/commands/deployments.js +0 -29
- package/build/src/commands/deployments.js.map +0 -1
- package/build/src/commands/list.d.ts +0 -9
- package/build/src/commands/list.js +0 -34
- package/build/src/commands/list.js.map +0 -1
- package/build/src/commands/login.d.ts +0 -15
- package/build/src/commands/login.js.map +0 -1
- package/build/src/commands/logout.d.ts +0 -5
- package/build/src/commands/logout.js.map +0 -1
- package/build/src/commands/logs.d.ts +0 -17
- package/build/src/commands/logs.js +0 -181
- package/build/src/commands/logs.js.map +0 -1
- package/build/src/commands/open.d.ts +0 -15
- package/build/src/commands/open.js +0 -89
- package/build/src/commands/open.js.map +0 -1
- package/build/src/commands/pull.d.ts +0 -10
- package/build/src/commands/pull.js.map +0 -1
- package/build/src/commands/push.d.ts +0 -11
- package/build/src/commands/push.js.map +0 -1
- package/build/src/commands/run.d.ts +0 -14
- package/build/src/commands/run.js +0 -130
- package/build/src/commands/run.js.map +0 -1
- package/build/src/commands/setting.d.ts +0 -8
- package/build/src/commands/setting.js +0 -53
- package/build/src/commands/setting.js.map +0 -1
- package/build/src/commands/status.d.ts +0 -9
- package/build/src/commands/status.js +0 -25
- package/build/src/commands/status.js.map +0 -1
- package/build/src/commands/undeploy.d.ts +0 -9
- package/build/src/commands/undeploy.js +0 -55
- package/build/src/commands/undeploy.js.map +0 -1
- package/build/src/commands/version.d.ts +0 -5
- package/build/src/commands/version.js +0 -22
- package/build/src/commands/version.js.map +0 -1
- package/build/src/commands/versions.d.ts +0 -5
- package/build/src/commands/versions.js +0 -41
- package/build/src/commands/versions.js.map +0 -1
- package/build/src/conf.d.ts +0 -40
- package/build/src/conf.js +0 -100
- package/build/src/conf.js.map +0 -1
- package/build/src/constants.d.ts +0 -6
- package/build/src/constants.js.map +0 -1
- package/build/src/dotfile.d.ts +0 -50
- package/build/src/dotfile.js +0 -71
- package/build/src/dotfile.js.map +0 -1
- package/build/src/files.d.ts +0 -70
- package/build/src/files.js +0 -364
- package/build/src/files.js.map +0 -1
- package/build/src/index.d.ts +0 -18
- package/build/src/index.js.map +0 -1
- package/build/src/inquirer.d.ts +0 -82
- package/build/src/inquirer.js +0 -111
- package/build/src/inquirer.js.map +0 -1
- package/build/src/manifest.d.ts +0 -123
- package/build/src/manifest.js +0 -142
- package/build/src/manifest.js.map +0 -1
- package/build/src/messages.d.ts +0 -110
- package/build/src/messages.js +0 -161
- package/build/src/messages.js.map +0 -1
- package/build/src/urls.d.ts +0 -21
- package/build/src/urls.js +0 -33
- package/build/src/urls.js.map +0 -1
- package/build/src/utils.d.ts +0 -102
- package/build/src/utils.js +0 -232
- package/build/src/utils.js.map +0 -1
- package/docs/develop.md +0 -94
- package/docs/esmodules.md +0 -81
- package/docs/running-locally.md +0 -31
- package/docs/settings.md +0 -56
- package/docs/typescript.md +0 -354
package/docs/typescript.md
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
# TypeScript
|
|
2
|
-
|
|
3
|
-
[TypeScript](https://www.typescriptlang.org/) is a typed superset of JavaScript that can compile to plain Apps Script.
|
|
4
|
-
Using TypeScript with your `clasp` project allows you to use features such as:
|
|
5
|
-
|
|
6
|
-
- Arrow functions
|
|
7
|
-
- Optional structural typing
|
|
8
|
-
- Classes
|
|
9
|
-
- Type inference
|
|
10
|
-
- Interfaces
|
|
11
|
-
- And more…
|
|
12
|
-
|
|
13
|
-
Starting with version `1.5.0`, Clasp allows **new** and **existing** Apps Script projects to use TypeScript.
|
|
14
|
-
|
|
15
|
-
> Note: Once you use TypeScript, you cannot develop on script.google.com (the [transpiled](https://en.wikipedia.org/wiki/Source-to-source_compiler) code).
|
|
16
|
-
|
|
17
|
-
> Warning: Apps Script's runtime/execution is different than Node or web browsers. In particular, you cannot use the terms `export` or `require` in the same way you would with Node. You cannot use `window` like in web browsers.
|
|
18
|
-
|
|
19
|
-
## Quickstart
|
|
20
|
-
|
|
21
|
-
This quickstart guide describes how to create a TypeScript project from scratch.
|
|
22
|
-
|
|
23
|
-
### Prerequisites
|
|
24
|
-
|
|
25
|
-
1. Ensure you have upgraded to clasp's version >= 1.5.0
|
|
26
|
-
- `clasp -v`
|
|
27
|
-
|
|
28
|
-
1. Install TypeScript definitions for Apps Script in your project's folder.
|
|
29
|
-
- `npm i -D @types/google-apps-script`
|
|
30
|
-
|
|
31
|
-
1. Create a file called `tsconfig.json` to enable TypeScript features:
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
{
|
|
35
|
-
"compilerOptions": {
|
|
36
|
-
"lib": ["esnext"],
|
|
37
|
-
"experimentalDecorators": true
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
(See [1](https://github.com/Microsoft/monaco-editor/issues/61#issuecomment-342359348) [2](https://code.visualstudio.com/docs/languages/jsconfig#_jsconfig-options) [esnext](https://basarat.gitbooks.io/typescript/docs/types/lib.d.ts.html))
|
|
43
|
-
|
|
44
|
-
### Create the TypeScript Project
|
|
45
|
-
|
|
46
|
-
Create a clasp project in an empty directory (or use an existing project):
|
|
47
|
-
|
|
48
|
-
```sh
|
|
49
|
-
clasp create --type standalone
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
Create a TypeScript file called `hello.ts` with the following contents:
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
const greeter = (person: string) => {
|
|
56
|
-
return `Hello, ${person}!`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function testGreeter() {
|
|
60
|
-
const user = 'Grant';
|
|
61
|
-
Logger.log(greeter(user));
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
> Note: This is a valid TypeScript file (but an invalid Apps Script file). That's OK.
|
|
66
|
-
|
|
67
|
-
### Push the project to the Apps Script server
|
|
68
|
-
|
|
69
|
-
Push the TypeScript file to the Apps Script server:
|
|
70
|
-
|
|
71
|
-
```sh
|
|
72
|
-
clasp push
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
> Note: clasp automatically transpiles `.ts` files to valid Apps Script files upon `clasp push`.
|
|
76
|
-
|
|
77
|
-
### Verify the project works on script.google.com
|
|
78
|
-
|
|
79
|
-
Open the Apps Script project on script.google.com:
|
|
80
|
-
|
|
81
|
-
```sh
|
|
82
|
-
clasp open
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
Notice how a transpiled version of your project was pushed to the Apps Script server.
|
|
86
|
-
|
|
87
|
-
Run `testGreeter()` and press `View` > `Logs` to view the logs to see the result.
|
|
88
|
-
|
|
89
|
-
## TypeScript Examples
|
|
90
|
-
|
|
91
|
-
This section lists TypeScript examples derived from [this guide](https://angular-2-training-book.rangle.io/handout/features/):
|
|
92
|
-
|
|
93
|
-
These features allow you to write Apps Script concisely with intelligent IDE errors and autocompletions.
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
// Optional Types
|
|
97
|
-
let isDone: boolean = false;
|
|
98
|
-
let height: number = 6;
|
|
99
|
-
let bob: string = "bob";
|
|
100
|
-
let list1: number[] = [1, 2, 3];
|
|
101
|
-
let list2: Array<number> = [1, 2, 3];
|
|
102
|
-
enum Color {Red, Green, Blue};
|
|
103
|
-
let c: Color = Color.Green;
|
|
104
|
-
let notSure: any = 4;
|
|
105
|
-
notSure = "maybe a string instead";
|
|
106
|
-
notSure = false; // okay, definitely a boolean
|
|
107
|
-
function showMessage(data: string): void { // Void
|
|
108
|
-
console.log(data);
|
|
109
|
-
}
|
|
110
|
-
showMessage('hello');
|
|
111
|
-
|
|
112
|
-
// Classes
|
|
113
|
-
class Hamburger {
|
|
114
|
-
constructor() {
|
|
115
|
-
// This is the constructor.
|
|
116
|
-
}
|
|
117
|
-
listToppings() {
|
|
118
|
-
// This is a method.
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Template strings
|
|
123
|
-
var name = 'Sam';
|
|
124
|
-
var age = 42;
|
|
125
|
-
console.log(`hello my name is ${name}, and I am ${age} years old`);
|
|
126
|
-
|
|
127
|
-
// Rest arguments
|
|
128
|
-
const buildName = (first: string, ...rest) => first + ' ' + rest.join(' ');
|
|
129
|
-
buildName('First', 'Second', 'Third');
|
|
130
|
-
|
|
131
|
-
// Spread operator (array)
|
|
132
|
-
let cde = ['c', 'd', 'e'];
|
|
133
|
-
let scale = ['a', 'b', ...cde, 'f', 'g']; // ['a', 'b', 'c', 'd', 'e', 'f', 'g']
|
|
134
|
-
|
|
135
|
-
// Spread operator (map)
|
|
136
|
-
let mapABC = { a: 5, b: 6, c: 3};
|
|
137
|
-
let mapABCD = { ...mapABC, d: 7}; // { a: 5, b: 6, c: 3, d: 7 }
|
|
138
|
-
|
|
139
|
-
// Destructure map
|
|
140
|
-
let jane = { firstName: 'Jane', lastName: 'Doe'};
|
|
141
|
-
let john = { firstName: 'John', lastName: 'Doe', middleName: 'Smith' }
|
|
142
|
-
function sayName({firstName, lastName, middleName = 'N/A'}) {
|
|
143
|
-
console.log(`Hello ${firstName} ${middleName} ${lastName}`)
|
|
144
|
-
}
|
|
145
|
-
sayName(jane) // -> Hello Jane N/A Doe
|
|
146
|
-
sayName(john) // -> Helo John Smith Doe
|
|
147
|
-
|
|
148
|
-
// Export (The export keyword is ignored)
|
|
149
|
-
export const pi = 3.141592;
|
|
150
|
-
|
|
151
|
-
// Google Apps Script Services
|
|
152
|
-
var doc = DocumentApp.create('Hello, world!');
|
|
153
|
-
doc.getBody().appendParagraph('This document was created by Google Apps Script.');
|
|
154
|
-
|
|
155
|
-
// Decorators
|
|
156
|
-
function Override(label: string) {
|
|
157
|
-
return function (target: any, key: string) {
|
|
158
|
-
Object.defineProperty(target, key, {
|
|
159
|
-
configurable: false,
|
|
160
|
-
get: () => label
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
class Test {
|
|
165
|
-
@Override('test') // invokes Override, which returns the decorator
|
|
166
|
-
name: string = 'pat';
|
|
167
|
-
}
|
|
168
|
-
let t = new Test();
|
|
169
|
-
console.log(t.name); // 'test'
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
After installing `@types/google-apps-script`, editors like Visual Studio Code autocomplete types:
|
|
173
|
-
|
|
174
|
-
```ts
|
|
175
|
-
var doc = DocumentApp.create('Hello, world!');
|
|
176
|
-
doc.getBody().appendParagraph('This document was created by Google Apps Script.');
|
|
177
|
-
Logger.log(doc.getUrl());
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
In this case, we could write the fully qualified type:
|
|
181
|
-
|
|
182
|
-
```ts
|
|
183
|
-
const doc: GoogleAppsScript.Document.Document = DocumentApp.create('Hello, world!');
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Or inferred type:
|
|
187
|
-
|
|
188
|
-
```ts
|
|
189
|
-
const doc = DocumentApp.create('Hello, world!');
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
In most cases, the inferred type is sufficient for Apps Script autocompletion.
|
|
193
|
-
|
|
194
|
-
## How it works
|
|
195
|
-
|
|
196
|
-
`clasp push` transpiles ES6+ into ES3 (using [`ts2gas`](https://github.com/grant/ts2gas)) before pushing files to the Apps Script server.
|
|
197
|
-
|
|
198
|
-
## Gotchas
|
|
199
|
-
|
|
200
|
-
### Advanced Services
|
|
201
|
-
|
|
202
|
-
Enabling advanced services modifies the `appsscript.json` file on script.google.com. After enabling an advanced service in the UI, copy the `appsscript.json` file from script.google.com into your editor to use the advanced services in your project.
|
|
203
|
-
|
|
204
|
-
Advanced Service should have TypeScript autocompletion.
|
|
205
|
-
|
|
206
|
-
### TypeScript Support
|
|
207
|
-
|
|
208
|
-
Currently, `clasp` supports [`typescript@3.8.2`](https://www.npmjs.com/package/typescript/v/3.8.2). If there is a feature in a newer TypeScript version that you'd like to support, or some experimental flag you'd like enabled, please open an issue.
|
|
209
|
-
|
|
210
|
-
#### TypeScript configuration
|
|
211
|
-
|
|
212
|
-
- You can create a TypeScript configuration file by creating a `tsconfig.json` file in the same folder as your `.clasp.json` file.
|
|
213
|
-
- Only the `"compilerOptions"` section is considered. Anything else is ignored.
|
|
214
|
-
|
|
215
|
-
By default `"compilerOptions"` uses these options:
|
|
216
|
-
|
|
217
|
-
```json
|
|
218
|
-
{
|
|
219
|
-
"isolatedModules": true,
|
|
220
|
-
"noLib": true,
|
|
221
|
-
"noResolve": true,
|
|
222
|
-
"target": "ES3",
|
|
223
|
-
"module": "None",
|
|
224
|
-
"noImplicitUseStrict": true,
|
|
225
|
-
"experimentalDecorators": true,
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
> Note that the options `isolatedModules`, `noLib`, `noResolve` and `module` cannot be changed.
|
|
230
|
-
|
|
231
|
-
##### V8 engine support
|
|
232
|
-
|
|
233
|
-
If your Apps Script project is configured to use the V8 Engine, you should set `"target": "ES2019"` in your `tsconfig.json`.
|
|
234
|
-
|
|
235
|
-
### Modules, exports and imports
|
|
236
|
-
|
|
237
|
-
Currently, Google Apps Script does **not** support ES modules. Hence the typical `export`/`import` pattern cannot be used and the example below will fail:
|
|
238
|
-
|
|
239
|
-
```ts
|
|
240
|
-
// module.ts
|
|
241
|
-
|
|
242
|
-
// `foo` is added to the `exports` object in the global namespace
|
|
243
|
-
export const foo = 'Hello from Module';
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
```ts
|
|
247
|
-
// main.ts
|
|
248
|
-
import { foo } from './module'; // this statement is ignored
|
|
249
|
-
|
|
250
|
-
// the variable `foo` does not exist in the global namespace
|
|
251
|
-
const bar = foo;
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
There are some possible workaround though:
|
|
255
|
-
|
|
256
|
-
#### The `exports` declaration workaround
|
|
257
|
-
|
|
258
|
-
This workaround makes TypeScript aware of the `exports` object and its "imported" content. Please be aware that this approach does not even remotely offer proper code isolation one would assume from using modules and can cause issues that will be very hard to debug.
|
|
259
|
-
|
|
260
|
-
```ts
|
|
261
|
-
declare const exports: typeof import('./module');
|
|
262
|
-
|
|
263
|
-
exports.foo; // address "imported" content as it will be visible when transpiled
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
#### The `namespace` statement workaround
|
|
267
|
-
|
|
268
|
-
This workaround takes advantage of TypeScript "namespaces" (formerly known as "internal module") and achieves proper code isolation.
|
|
269
|
-
|
|
270
|
-
Namespace definition can be nested, spread over multiple files and do not need any `import`/`require` statement to be used.
|
|
271
|
-
|
|
272
|
-
```ts
|
|
273
|
-
// module.ts
|
|
274
|
-
namespace Module {
|
|
275
|
-
export function foo() {}
|
|
276
|
-
function bar() {} // this function can only be addressed from within the `Module` namespace
|
|
277
|
-
}
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
```ts
|
|
281
|
-
// anyFiles.ts
|
|
282
|
-
Module.foo(); // address a namespace's exported content directly
|
|
283
|
-
|
|
284
|
-
const nameIWantForMyImports = Module.foo; // to simulate `import` with renaming
|
|
285
|
-
nameIWantForMyImports();
|
|
286
|
-
```
|
|
287
|
-
|
|
288
|
-
For a more detailed example on how `namespace`s can be used in a project you can visit [ts-gas-project-starter](https://github.com/PopGoesTheWza/ts-gas-project-starter)
|
|
289
|
-
|
|
290
|
-
#### The third party build-chain workaround
|
|
291
|
-
|
|
292
|
-
Here the idea is to use third party tools ([webpack](https://webpack.js.org/), [rollup.js](https://rollupjs.org/), [gulp](https://gulpjs.com/), etc.) to do the following:
|
|
293
|
-
|
|
294
|
-
1. parse your code and indentify module used (`export`and `import`)
|
|
295
|
-
1. *(optional)* do some tree shaking in order to remove unused code
|
|
296
|
-
1. pack the result into a single javascript package
|
|
297
|
-
|
|
298
|
-
> At one of the steps above, transpilling TypeScript into JavaScript must occur (either by using TypeScript or [Babel](https://babeljs.io/)) but which precise step will be defined by the set of third party tools you choose and how you define your build chain.
|
|
299
|
-
|
|
300
|
-
For an example on how this could be set up using [rollup.js](https://rollupjs.org/), see [esmodules.md](./esmodules.md).
|
|
301
|
-
|
|
302
|
-
Documenting in detail any solution with third party tools is currently beyond the scope of this document. If you happen to setup such a build chain and want to share it with the community, please open an issue so that it can be reviewed and evaluated for completing the documentation.
|
|
303
|
-
|
|
304
|
-
### Apps Script Libraries and TypeScript
|
|
305
|
-
|
|
306
|
-
If your project contains libraries referenced in `appsscript.json`, TypeScript will throw errors for the library names or types it cannot resolve, e.g. `[ts] Cannot find name 'OAuth2'. [2304]`. Libraries have their own types and are not part of `@types/google-apps-script`. These libraries are only resolved once the script is deployed upstream with `clasp push`.
|
|
307
|
-
|
|
308
|
-
If the @types npm package exists for a GAS library, you can install it as so:
|
|
309
|
-
|
|
310
|
-
```
|
|
311
|
-
npm install -D @types/google-apps-script-oauth2
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
Add the types reference to your `tsconfig.json` file:
|
|
315
|
-
|
|
316
|
-
```
|
|
317
|
-
{
|
|
318
|
-
"compilerOptions": {
|
|
319
|
-
"types": ["google-apps-script", "google-apps-script-oauth2"],
|
|
320
|
-
"strict": true
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
Not all libraries will have type definitions, so you may have to create your own. Refer to the [Outdated Types](##Outdated-Types) section below for more details.
|
|
327
|
-
|
|
328
|
-
If you do not want to generate types, a lazier workaround for this error is to ignore the line causing the TypeScript error by adding a line comment `// @ts-ignore` above the line. This can be done as so:
|
|
329
|
-
|
|
330
|
-
```ts
|
|
331
|
-
function getOAuthService() {
|
|
332
|
-
// Ignore OAuth2 library resolution when working locally with clasp and TypeScript
|
|
333
|
-
// @ts-ignore
|
|
334
|
-
return OAuth2.createService('Auth0');
|
|
335
|
-
}
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
## Outdated Types
|
|
339
|
-
|
|
340
|
-
TypeScript types for Apps Script are currently generated manually.
|
|
341
|
-
|
|
342
|
-
If you see outdated TypeScript types, you can help update them by contributing to [@types/google-apps-script](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/google-apps-script).
|
|
343
|
-
|
|
344
|
-
### How to Generate Types
|
|
345
|
-
|
|
346
|
-
1. Fork [DefinitelyTyped/DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped)
|
|
347
|
-
1. Run the types generator by following the instructions at [motemen/dts-google-apps-script](https://github.com/motemen/dts-google-apps-script)
|
|
348
|
-
1. Copy the type files to your fork of `DefinitelyTyped/DefinitelyTyped`.
|
|
349
|
-
1. View the diff (`git diff`), and make sure that the types look OK.
|
|
350
|
-
1. Make a PR and ask [@grant](https://github.com/grant) for review.
|
|
351
|
-
|
|
352
|
-
## Further Reading
|
|
353
|
-
|
|
354
|
-
- Consider using a linter like [`gts`](https://github.com/google/gts) to increase the quality of your TypeScript projects.
|