Repository: electron/electron (language: cpp)

Issue:
Improve Type Union Typings in the Docs
[The phrasings that `electron/docs-parser` recognizes for string union types](https://github.com/electron/docs-parser/blob/c56164b4cebcf010306e0458729bf179bf69e650/src/markdown-helpers.ts#L459) is fairly narrow, and it looks like there's a handful of places in the docs where the phrasing is not being picked up as string union types.

Fix these and add smoke tests with `// @ts-expect-error` to ensure type unions are being used. See #38336 for an example.

Alternatively, extend the phrasings that `electron/docs-parser` recognizes, and add the smoke tests.

A (possibly non-exhaustive) list of ones which aren't being picked up. There's [an upstream issue](https://github.com/electron/docs-parser/issues/88) preventing certain values from being picked up.

https://github.com/electron/electron/blob/2a16c73834358f85ef20c07e50dfb5178c30bb1e/docs/api/webview-tag.md?plain=1#L1091-L1093

https://github.com/electron/electron/blob/2a16c73834358f85ef20c07e50dfb5178c30bb1e/docs/api/web-contents.md?plain=1#L796-L798

https://github.com/electron/electron/blob/2a16c73834358f85ef20c07e50dfb5178c30bb1e/docs/api/native-image.md?plain=1#L308-L309

https://github.com/electron/electron/blob/2a16c73834358f85ef20c07e50dfb5178c30bb1e/docs/api/session.md?plain=1#L577-L580

https://github.com/electron/electron/blob/2a16c73834358f85ef20c07e50dfb5178c30bb1e/docs/api/session.md?plain=1#L581-L582

https://github.com/electron/electron/blob/e08c583dea42ce70c926825a2f6d455bbddf2089/docs/api/desktop-capturer.md?plain=1#L91-L92


Discussion / hints:
I wanna pick this issue, allow me to contribute it
hey, I want to solve this issue can you please assign me this
Anyone working on this?

If anyone wants to work on this, please just create a PR rather then comment here. If a PR mentions this issue it will be visible here, so in the absence of said linked PRs, please feel free to create a PR - we don't assign issues like this to external contributors. 🙂

Fix patch:
diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md
index 32b881516ae54..078d4f980b441 100644
--- a/docs/api/desktop-capturer.md
+++ b/docs/api/desktop-capturer.md
@@ -91,7 +91,7 @@ The `desktopCapturer` module has the following methods:
 
 * `options` Object
   * `types` string[] - An array of strings that lists the types of desktop sources
-    to be captured, available types are `screen` and `window`.
+    to be captured, available types can be `screen` and `window`.
   * `thumbnailSize` [Size](structures/size.md) (optional) - The size that the media source thumbnail
     should be scaled to. Default is `150` x `150`. Set width or height to 0 when you do not need
     the thumbnails. This will save the processing time required for capturing the content of each
diff --git a/docs/api/native-image.md b/docs/api/native-image.md
index 84660c5da77b7..d31b39f1c7784 100644
--- a/docs/api/native-image.md
+++ b/docs/api/native-image.md
@@ -306,7 +306,7 @@ Returns `NativeImage` - The cropped image.
   * `width` Integer (optional) - Defaults to the image's width.
   * `height` Integer (optional) - Defaults to the image's height.
   * `quality` string (optional) - The desired quality of the resize image.
-    Possible values are `good`, `better`, or `best`. The default is `best`.
+    Possible values include `good`, `better`, or `best`. The default is `best`.
     These values express a desired quality/speed tradeoff. They are translated
     into an algorithm-specific method that depends on the capabilities
     (CPU, GPU) of the underlying platform. It is possible for all three methods
diff --git a/docs/api/session.md b/docs/api/session.md
index df59bf0886a62..7be9461b10a40 100644
--- a/docs/api/session.md
+++ b/docs/api/session.md
@@ -574,11 +574,11 @@ Clears the session’s HTTP cache.
 * `options` Object (optional)
   * `origin` string (optional) - Should follow `window.location.origin`’s representation
     `scheme://host:port`.
-  * `storages` string[] (optional) - The types of storages to clear, can contain:
+  * `storages` string[] (optional) - The types of storages to clear, can be
     `cookies`, `filesystem`, `indexdb`, `localstorage`,
     `shadercache`, `websql`, `serviceworkers`, `cachestorage`. If not
     specified, clear all storage types.
-  * `quotas` string[] (optional) - The types of quotas to clear, can contain:
+  * `quotas` string[] (optional) - The types of quotas to clear, can be
     `temporary`, `syncable`. If not specified, clear all quotas.
 
 Returns `Promise<void>` - resolves when the storage data has been cleared.
@@ -1113,7 +1113,7 @@ app.whenReady().then(() => {
 
 * `handler` Function\<string[]> | null
   * `details` Object
-    * `protectedClasses` string[] - The current list of protected USB classes. Possible class values are:
+    * `protectedClasses` string[] - The current list of protected USB classes. Possible class values include:
       * `audio`
       * `audio-video`
       * `hid`
diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md
index fb123983169d7..cb046fb8fd9f2 100644
--- a/docs/api/web-contents.md
+++ b/docs/api/web-contents.md
@@ -795,7 +795,7 @@ Returns:
   * `frameCharset` string - The character encoding of the frame on which the
     menu was invoked.
   * `inputFieldType` string - If the context menu was invoked on an input
-    field, the type of that field. Possible values are `none`, `plainText`,
+    field, the type of that field. Possible values include `none`, `plainText`,
     `password`, `other`.
   * `spellcheckEnabled` boolean - If the context is editable, whether or not spellchecking is enabled.
   * `menuSourceType` string - Input source that invoked the context menu.
diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md
index 4a71c998f54b8..74b8c1519dd25 100644
--- a/docs/api/webview-tag.md
+++ b/docs/api/webview-tag.md
@@ -1091,7 +1091,7 @@ Returns:
   * `frameCharset` string - The character encoding of the frame on which the
     menu was invoked.
   * `inputFieldType` string - If the context menu was invoked on an input
-    field, the type of that field. Possible values are `none`, `plainText`,
+    field, the type of that field. Possible values include `none`, `plainText`,
     `password`, `other`.
   * `spellcheckEnabled` boolean - If the context is editable, whether or not spellchecking is enabled.
   * `menuSourceType` string - Input source that invoked the context menu.
diff --git a/spec/api-session-spec.ts b/spec/api-session-spec.ts
index 6768077027c50..840748167a24e 100644
--- a/spec/api-session-spec.ts
+++ b/spec/api-session-spec.ts
@@ -252,12 +252,11 @@ describe('session module', () => {
     it('clears localstorage data', async () => {
       const w = new BrowserWindow({ show: false, webPreferences: { nodeIntegration: true } });
       await w.loadFile(path.join(fixtures, 'api', 'localstorage.html'));
-      const options = {
+      await w.webContents.session.clearStorageData({
         origin: 'file://',
         storages: ['localstorage'],
-        quotas: ['persistent']
-      };
-      await w.webContents.session.clearStorageData(options);
+        quotas: ['temporary']
+      });
       while (await w.webContents.executeJavaScript('localStorage.length') !== 0) {
         // The storage clear isn't instantly visible to the renderer, so keep
         // trying until it is.
diff --git a/spec/ts-smoke/electron/main.ts b/spec/ts-smoke/electron/main.ts
index 05829f4d6e212..27ea0da6c3cd1 100644
--- a/spec/ts-smoke/electron/main.ts
+++ b/spec/ts-smoke/electron/main.ts
@@ -526,6 +526,10 @@ dialog.showMessageBoxSync(win3, { message: 'test', type: 'foo' });
 
 ipcMain.handle('get-sources', (event, options) => desktopCapturer.getSources(options));
 
+desktopCapturer.getSources({ types: ['window', 'screen'] });
+// @ts-expect-error Invalid type value
+desktopCapturer.getSources({ types: ['unknown'] });
+
 // global-shortcut
 // https://github.com/electron/electron/blob/main/docs/api/global-shortcut.md
 
@@ -1030,6 +1034,12 @@ appIcon4.destroy();
 const image2 = nativeImage.createFromPath('/Users/somebody/images/icon.png');
 console.log(image2.getSize());
 
+image2.resize({ quality: 'best' });
+image2.resize({ quality: 'better' });
+image2.resize({ quality: 'good' });
+// @ts-expect-error Invalid type value
+image2.resize({ quality: 'bad' });
+
 // process
 // https://github.com/electron/electron/blob/main/docs/api/process.md
 
@@ -1133,6 +1143,16 @@ shell.writeShortcutLink('/home/user/Desktop/shortcut.lnk', 'update', shell.readS
 // session
 // https://github.com/electron/electron/blob/main/docs/api/session.md
 
+session.defaultSession.clearStorageData({ storages: ['cookies', 'filesystem'] });
+session.defaultSession.clearStorageData({ storages: ['localstorage', 'indexdb', 'serviceworkers'] });
+session.defaultSession.clearStorageData({ storages: ['shadercache', 'websql', 'cachestorage'] });
+// @ts-expect-error Invalid type value
+session.defaultSession.clearStorageData({ storages: ['wrong_path'] });
+
+session.defaultSession.clearStorageData({ quotas: ['syncable', 'temporary'] });
+// @ts-expect-error Invalid type value
+session.defaultSession.clearStorageData({ quotas: ['bad_type'] });
+
 session.defaultSession.on('will-download', (event, item, webContents) => {
   console.log('will-download', webContents.id);
   event.preventDefault();


Test patch: