Skip to content

Commit 40c7c69

Browse files
authored
fix: declare undefined explicitly (#7)
1 parent af7a4b9 commit 40c7c69

File tree

1 file changed

+86
-78
lines changed

1 file changed

+86
-78
lines changed

index.d.ts

Lines changed: 86 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ declare interface VMScriptGMInfoPlatform {
3131
* Only present in browsers that implement this API (Chromium >= 90).
3232
* @since VM2.27.0
3333
*/
34-
fullVersionList?: { brand: string; version: string }[];
34+
fullVersionList?: { brand: string; version: string }[] | undefined;
3535
/**
3636
* A copy of `navigator.userAgentData.mobile` from the background script of the extension,
3737
* so it's not affected by devtools of the web page tab.
3838
* Only present in browsers that implement this API (Chromium >= 90).
3939
* @since VM2.27.0
4040
*/
41-
mobile?: boolean;
41+
mobile?: boolean | undefined;
4242
os: 'mac' | 'win' | 'android' | 'cros' | 'linux' | 'openbsd' | 'fuchsia';
4343
}
4444

@@ -47,31 +47,31 @@ declare interface VMScriptGMInfoPlatform {
4747
* Non-optional string property will be an empty string '' if omitted.
4848
*/
4949
declare interface VMScriptGMInfoScriptMeta {
50-
antifeature?: string[];
51-
author?: string;
52-
compatible?: string[];
53-
connect?: string[];
50+
antifeature?: string[] | undefined;
51+
author?: string | undefined;
52+
compatible?: string[] | undefined;
53+
connect?: string[] | undefined;
5454
description: string;
55-
downloadURL?: string;
55+
downloadURL?: string | undefined;
5656
excludeMatches: string[];
5757
excludes: string[];
5858
/** Empty is the same as `@grant none` */
5959
grant: string[];
6060
/** Use homepageURL instead */
61-
homepage?: string;
62-
homepageURL?: string;
63-
icon?: string;
61+
homepage?: string | undefined;
62+
homepageURL?: string | undefined;
63+
icon?: string | undefined;
6464
includes: string[];
6565
matches: string[];
6666
name: string;
6767
namespace: string;
68-
noframes?: boolean;
68+
noframes?: boolean | undefined;
6969
require: string[];
7070
resources: { name: string; url: string }[];
7171
runAt: VMScriptRunAt | '';
72-
supportURL?: string;
73-
unwrap?: boolean;
74-
updateURL?: string;
72+
supportURL?: string | undefined;
73+
unwrap?: boolean | undefined;
74+
updateURL?: string | undefined;
7575
version: string;
7676
}
7777

@@ -126,12 +126,14 @@ declare interface VMScriptGMInfoObject {
126126
*
127127
* @since VM2.20.2
128128
*/
129-
userAgentData?: {
130-
brands: { brand: string; version: string }[];
131-
mobile: boolean;
132-
platform: string;
133-
getHighEntropyValues(hints: string[]): Promise<UADataValues>;
134-
};
129+
userAgentData?:
130+
| {
131+
brands: { brand: string; version: string }[];
132+
mobile: boolean;
133+
platform: string;
134+
getHighEntropyValues(hints: string[]): Promise<UADataValues>;
135+
}
136+
| undefined;
135137
}
136138

137139
/**
@@ -143,7 +145,7 @@ declare const GM_info: VMScriptGMInfoObject;
143145
declare function GM_log(...args: any): void;
144146

145147
/** Retrieves a value for current script from storage. */
146-
declare function GM_getValue<T>(name: string, defaultValue?: T): T;
148+
declare function GM_getValue<T>(name: string, defaultValue?: T | undefined): T;
147149
/** @since VM2.19.1 */
148150
declare function GM_getValues(names: string[]): GenericObject;
149151
/** @since VM2.19.1 */
@@ -195,7 +197,7 @@ declare function GM_getResourceURL(
195197
* - If `true`, returns a `blob:` URL. It's short and cacheable, so it's good for reusing in multiple DOM elements.
196198
* - If `false`, returns a `data:` URL. It's long so reusing it in DOM may be less performant due to the lack of caching, but it's particularly handy for direct synchronous decoding of the data on sites that forbid fetching `blob:` in their CSP.
197199
*/
198-
isBlobUrl?: boolean,
200+
isBlobUrl?: boolean | undefined,
199201
): string;
200202

201203
/**
@@ -219,7 +221,7 @@ declare function GM_addElement(
219221
/** A tag name like `script`. Any valid HTML tag can be used, but the only motivation for this API was to add `script`, `link`, `style` elements when they are disallowed by a strict `Content-Security-Policy` of the site e.g. github.com, twitter.com. */
220222
tagName: string,
221223
/** The keys are HTML attributes, not DOM properties, except `textContent` which sets DOM property `textContent`. The values are strings so if you want to assign a private function to `onload` you can do it after the element is created. */
222-
attributes?: Record<string, string>,
224+
attributes?: Record<string, string> | undefined,
223225
): HTMLElement;
224226
declare function GM_addElement(
225227
/**
@@ -235,15 +237,15 @@ declare function GM_addElement(
235237
/** A tag name like `script`. Any valid HTML tag can be used, but the only motivation for this API was to add `script`, `link`, `style` elements when they are disallowed by a strict `Content-Security-Policy` of the site e.g. github.com, twitter.com. */
236238
tagName: string,
237239
/** The keys are HTML attributes, not DOM properties, except `textContent` which sets DOM property `textContent`. The values are strings so if you want to assign a private function to `onload` you can do it after the element is created. */
238-
attributes?: Record<string, string>,
240+
attributes?: Record<string, string> | undefined,
239241
): HTMLElement;
240242

241243
/** Appends and returns a `<style>` element with the specified CSS. */
242244
declare function GM_addStyle(css: string): HTMLStyleElement;
243245

244246
declare interface VMScriptGMTabControl {
245247
/** Сan be assigned to a function. If provided, it will be called when the opened tab is closed. */
246-
onclose?: () => void;
248+
onclose?: (() => void) | undefined;
247249
/** Whether the opened tab is closed. */
248250
closed: boolean;
249251
/** A function to explicitly close the opened tab. */
@@ -252,32 +254,32 @@ declare interface VMScriptGMTabControl {
252254

253255
declare interface VMScriptGMTabOptions {
254256
/** Make the new tab active (i.e. open in foreground). Default as `true`. */
255-
active?: boolean;
257+
active?: boolean | undefined;
256258
/**
257259
* Firefox only.
258260
*
259261
* - not specified = reuse script's tab container
260262
* - `0` = default (main) container
261263
* - `1`, `2`, etc. = internal container index
262264
*/
263-
container?: number;
265+
container?: number | undefined;
264266
/** Insert the new tab next to the current tab and set its `openerTab` so when it's closed the original tab will be focused automatically. When `false` or not specified, the usual browser behavior is to open the tab at the end of the tab list. Default as `true`. */
265-
insert?: boolean;
267+
insert?: boolean | undefined;
266268
/** Pin the tab (i.e. show without a title at the beginning of the tab list). Default as `false`. */
267-
pinned?: boolean;
269+
pinned?: boolean | undefined;
268270
}
269271

270272
/** Opens URL in a new tab. */
271273
declare function GM_openInTab(
272274
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
273275
url: string,
274-
options?: VMScriptGMTabOptions,
276+
options?: VMScriptGMTabOptions | undefined,
275277
): VMScriptGMTabControl;
276278
declare function GM_openInTab(
277279
/** The URL to open in a new tab. URL relative to current page is also allowed. Note: Firefox does not support data URLs. */
278280
url: string,
279281
/** Open the tab in background. Note, this is a reverse of the first usage method so for example `true` is the same as `{ active: false }`. */
280-
openInBackground?: boolean,
282+
openInBackground?: boolean | undefined,
281283
): VMScriptGMTabControl;
282284

283285
/**
@@ -291,16 +293,18 @@ declare function GM_registerMenuCommand(
291293
/** Callback function when the command is clicked in the menu. */
292294
onClick: (event: MouseEvent | KeyboardEvent) => void,
293295
/** @since VM2.15.9 */
294-
options?: {
295-
/** Default: the `caption` parameter.
296-
* In 2.15.9-2.16.1 the default was a randomly generated string. */
297-
id?: string;
298-
/** A hint shown in the status bar when hovering the command. */
299-
title?: string;
300-
/** Default: `true`.
301-
* Whether to auto-close the popup after the user invoked the command. */
302-
autoClose?: boolean;
303-
},
296+
options?:
297+
| {
298+
/** Default: the `caption` parameter.
299+
* In 2.15.9-2.16.1 the default was a randomly generated string. */
300+
id?: string | undefined;
301+
/** A hint shown in the status bar when hovering the command. */
302+
title?: string | undefined;
303+
/** Default: `true`.
304+
* Whether to auto-close the popup after the user invoked the command. */
305+
autoClose?: boolean | undefined;
306+
}
307+
| undefined,
304308
): string;
305309
/** Unregisters a command which has been registered to Violentmonkey popup menu. */
306310
declare function GM_unregisterMenuCommand(
@@ -321,12 +325,12 @@ declare interface VMScriptGMNotificationOptions {
321325
/** Main text of the notification. */
322326
text: string;
323327
/** Title of the notification. */
324-
title?: string;
328+
title?: string | undefined;
325329
/** URL of an image to show in the notification. */
326-
image?: string;
330+
image?: string | undefined;
327331
/** No sounds/vibrations when showing the notification.
328332
* @since VM2.15.2, Chrome 70. */
329-
silent?: boolean;
333+
silent?: boolean | undefined;
330334
/**
331335
* Unique name of the notification, e.g. 'abc', same as the web Notification API.
332336
* Names are scoped to each userscript i.e. your tag won't clash with another script's tag.
@@ -335,23 +339,23 @@ declare interface VMScriptGMNotificationOptions {
335339
* and your notification had `zombieTimeout`).
336340
* @since VM2.15.4
337341
*/
338-
tag?: string;
342+
tag?: string | undefined;
339343
/**
340344
* Number of milliseconds to keep the notification after the userscript "dies",
341345
* i.e. when its tab or frame is reloaded/closed/navigated. If not specified or invalid,
342346
* the default behavior is to immediately remove the notifications.
343347
* @since VM2.15.4
344348
*/
345-
zombieTimeout?: number;
349+
zombieTimeout?: number | undefined;
346350
/**
347351
* URL to open when a zombie notification is clicked, see `zombieTimeout` for more info.
348352
* @since VM2.16.1
349353
*/
350-
zombieUrl?: string;
354+
zombieUrl?: string | undefined;
351355
/** Callback when the notification is clicked by user. */
352-
onclick?: () => void;
356+
onclick?: (() => void) | undefined;
353357
/** Callback when the notification is closed, either by user or by system. */
354-
ondone?: () => void;
358+
ondone?: (() => void) | undefined;
355359
}
356360

357361
/** Shows an HTML5 desktop notification. */
@@ -362,19 +366,19 @@ declare function GM_notification(
362366
/** Main text of the notification. */
363367
text: string,
364368
/** Title of the notification. */
365-
title?: string,
369+
title?: string | undefined,
366370
/** URL of an image to show in the notification. */
367-
image?: string,
371+
image?: string | undefined,
368372
/** Callback when the notification is clicked by user. */
369-
onclick?: () => void,
373+
onclick?: (() => void) | undefined,
370374
): VMScriptGMNotificationControl;
371375

372376
/** Sets data to system clipboard. */
373377
declare function GM_setClipboard(
374378
/** The data to be copied to system clipboard. */
375379
data: string,
376380
/** The MIME type of data to copy. Default as `text/plain`. */
377-
type?: string,
381+
type?: string | undefined,
378382
): void;
379383

380384
/**
@@ -406,11 +410,11 @@ declare interface VMScriptResponseObject<T> {
406410
responseXML: Document | null;
407411
/** The final URL after redirection. */
408412
finalUrl: string;
409-
lengthComputable?: boolean;
410-
loaded?: number;
411-
total?: number;
413+
lengthComputable?: boolean | undefined;
414+
loaded?: number | undefined;
415+
total?: number | undefined;
412416
/** The same `context` object you specified in `details`. */
413-
context?: unknown;
417+
context?: unknown | undefined;
414418
}
415419

416420
type TypedArray =
@@ -430,9 +434,9 @@ interface GMRequestBase<T> {
430434
/** URL relative to current page is also allowed. */
431435
url: string;
432436
/** User for authentication. */
433-
user?: string;
437+
user?: string | undefined;
434438
/** Password for authentication. */
435-
password?: string;
439+
password?: string | undefined;
436440
/**
437441
* Some special headers are also allowed:
438442
*
@@ -442,28 +446,28 @@ interface GMRequestBase<T> {
442446
* - `Referer`
443447
* - `User-Agent`
444448
*/
445-
headers?: Record<string, string>;
449+
headers?: Record<string, string> | undefined;
446450
/** Time to wait for the request, none by default. */
447-
timeout?: number;
451+
timeout?: number | undefined;
448452
/** Can be an object and will be assigned to context of the response object. */
449-
context?: unknown;
453+
context?: unknown | undefined;
450454
/** When set to `true`, no cookie will be sent with the request and the response cookies will be ignored. The default value is `false`. */
451-
anonymous?: boolean;
452-
onabort?: (resp: VMScriptResponseObject<T>) => void;
453-
onerror?: (resp: VMScriptResponseObject<T>) => void;
454-
onload?: (resp: VMScriptResponseObject<T>) => void;
455-
onloadend?: (resp: VMScriptResponseObject<T>) => void;
456-
onloadstart?: (resp: VMScriptResponseObject<T>) => void;
457-
onprogress?: (resp: VMScriptResponseObject<T>) => void;
458-
onreadystatechange?: (resp: VMScriptResponseObject<T>) => void;
459-
ontimeout?: (resp: VMScriptResponseObject<T>) => void;
455+
anonymous?: boolean | undefined;
456+
onabort?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
457+
onerror?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
458+
onload?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
459+
onloadend?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
460+
onloadstart?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
461+
onprogress?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
462+
onreadystatechange?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
463+
ontimeout?: ((resp: VMScriptResponseObject<T>) => void) | undefined;
460464
}
461465

462466
declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
463467
/** HTTP method, default as `GET`. */
464-
method?: string;
468+
method?: string | undefined;
465469
/** A MIME type to specify with the request. */
466-
overrideMimeType?: string;
470+
overrideMimeType?: string | undefined;
467471
/**
468472
* One of the following:
469473
*
@@ -473,7 +477,7 @@ declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
473477
* - `arraybuffer`
474478
* - `document`
475479
*/
476-
responseType?: VMScriptResponseType;
480+
responseType?: VMScriptResponseType | undefined;
477481
/** Data to send with the request, usually for `POST` and `PUT` requests. */
478482
data?:
479483
| string
@@ -483,9 +487,10 @@ declare interface VMScriptGMXHRDetails<T> extends GMRequestBase<T> {
483487
| FormData
484488
| ReadableStream
485489
| TypedArray
486-
| URLSearchParams;
490+
| URLSearchParams
491+
| undefined;
487492
/** Send the `data` string as a `blob`. This is for compatibility with Tampermonkey/Greasemonkey, where only `string` type is allowed in `data`. */
488-
binary?: boolean;
493+
binary?: boolean | undefined;
489494
}
490495

491496
/** Makes a request like XMLHttpRequest, with some special capabilities, not restricted by same-origin policy. */
@@ -533,12 +538,15 @@ declare interface VMScriptGMObjectVMExtensions {
533538
declare interface VMScriptGMObject extends VMScriptGMObjectVMExtensions {
534539
unsafeWindow: Window;
535540
info: typeof GM_info;
536-
getValue: <T>(name: string, defaultValue?: T) => Promise<T>;
541+
getValue: <T>(name: string, defaultValue?: T | undefined) => Promise<T>;
537542
setValue: <T>(name: string, value: T) => Promise<void>;
538543
deleteValue: (name: string) => Promise<void>;
539544
listValues: () => Promise<string[]>;
540545
registerMenuCommand: typeof GM_registerMenuCommand;
541-
getResourceUrl: (name: string, isBlobUrl?: boolean) => Promise<string>;
546+
getResourceUrl: (
547+
name: string,
548+
isBlobUrl?: boolean | undefined,
549+
) => Promise<string>;
542550
notification: typeof GM_notification;
543551
openInTab: typeof GM_openInTab;
544552
setClipboard: typeof GM_setClipboard;

0 commit comments

Comments
 (0)