Skip to content

Commit

Permalink
fix: ensure the typescript definitions only export correct value types
Browse files Browse the repository at this point in the history
In typescript there are two main types of "types" you can export, value types (class, const) and definition types (type, interface).  The typescript compiler will let anything declared via const or class be used as a value.  Unfortunately we were exporting a bunch of things (see the diff) as class/const when they weren't actually exported values. This lead to typescript being happy but the runtime throwing errors (not something we want).

This change passes "exported-in" context through our docs, to the parser and then to the definitions generator to ensure we only mark things as exported in the ts defs that we actually export.

Fixes #22167
  • Loading branch information
MarshallOfSound committed Apr 18, 2021
1 parent 1e1884f commit 384966e
Show file tree
Hide file tree
Showing 37 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion docs/api/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Control your application's event lifecycle.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

The following example shows how to quit the application when the last window is
closed:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/auto-updater.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Enable apps to automatically update themselves.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

**See also: [A detailed guide about how to implement updates in your application](../tutorial/updates.md).**

Expand Down
2 changes: 1 addition & 1 deletion docs/api/browser-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Create and control views.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

A `BrowserView` can be used to embed additional web content into a
[`BrowserWindow`](browser-window.md). It is like a child window, except that it is positioned
Expand Down
2 changes: 1 addition & 1 deletion docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ state is `hidden` in order to minimize power consumption.

> Create and control browser windows.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

`BrowserWindow` is an [EventEmitter][event-emitter].

Expand Down
2 changes: 1 addition & 1 deletion docs/api/clipboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Perform copy and paste operations on the system clipboard.
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)
Exported in: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)

On Linux, there is also a `selection` clipboard. To manipulate it
you need to pass `selection` to each method:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/content-tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Collect tracing data from Chromium to find performance bottlenecks and slow operations.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

This module does not include a web interface. To view recorded traces, use
[trace viewer][], available at `chrome://tracing` in Chrome.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/context-bridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Create a safe, bi-directional, synchronous bridge across isolated contexts
Process: [Renderer](../glossary.md#renderer-process)
Exported in: [Renderer](../glossary.md#renderer-process)

An example of exposing an API to a renderer from an isolated preload script is given below:

Expand Down
2 changes: 1 addition & 1 deletion docs/api/crash-reporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Submit crash reports to a remote server.
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)
Exported in: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)

The following is an example of setting up Electron to automatically submit
crash reports to a remote server:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/desktop-capturer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
> Access information about media sources that can be used to capture audio and
> video from the desktop using the [`navigator.mediaDevices.getUserMedia`] API.
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)
Exported in: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)

The following example shows how to capture video from a desktop window whose
title is `Electron`:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Display native system dialogs for opening and saving files, alerting, etc.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

An example of showing a dialog to select multiple files:

Expand Down
2 changes: 1 addition & 1 deletion docs/api/global-shortcut.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Detect keyboard events when the application does not have keyboard focus.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

The `globalShortcut` module can register/unregister a global keyboard shortcut
with the operating system so that you can customize the operations for various
Expand Down
2 changes: 1 addition & 1 deletion docs/api/in-app-purchase.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> In-app purchases on Mac App Store.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

## Events

Expand Down
2 changes: 1 addition & 1 deletion docs/api/ipc-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Communicate asynchronously from the main process to renderer processes.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

The `ipcMain` module is an [Event Emitter][event-emitter]. When used in the main
process, it handles asynchronous and synchronous messages sent from a renderer
Expand Down
2 changes: 1 addition & 1 deletion docs/api/ipc-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Communicate asynchronously from a renderer process to the main process.
Process: [Renderer](../glossary.md#renderer-process)
Exported in: [Renderer](../glossary.md#renderer-process)

The `ipcRenderer` module is an [EventEmitter][event-emitter]. It provides a few
methods so you can send synchronous and asynchronous messages from the render
Expand Down
2 changes: 1 addition & 1 deletion docs/api/menu-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Add items to native application menus and context menus.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

See [`Menu`](menu.md) for examples.

Expand Down
2 changes: 1 addition & 1 deletion docs/api/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Create native application menus and context menus.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

### `new Menu()`

Expand Down
2 changes: 1 addition & 1 deletion docs/api/message-channel-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ channel messaging.

## Class: MessageChannelMain

Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

Example:

Expand Down
2 changes: 1 addition & 1 deletion docs/api/native-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Create tray, dock, and application icons using PNG or JPG files.
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)
Exported in: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process)

In Electron, for the APIs that take images, you can pass either file paths or
`NativeImage` instances. An empty image will be used when `null` is passed.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/native-theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Read and respond to changes in Chromium's native color theme.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

## Events

Expand Down
2 changes: 1 addition & 1 deletion docs/api/net-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Logging network events for a session.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

```javascript
const { netLog } = require('electron')
Expand Down
2 changes: 1 addition & 1 deletion docs/api/net.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Issue HTTP/HTTPS requests using Chromium's native networking library
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

The `net` module is a client-side API for issuing HTTP(S) requests. It is
similar to the [HTTP](https://nodejs.org/api/http.html) and
Expand Down
2 changes: 1 addition & 1 deletion docs/api/notification.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you want to show Notifications from a renderer process you should use the [HT

> Create OS desktop notifications
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

`Notification` is an [EventEmitter][event-emitter].

Expand Down
2 changes: 1 addition & 1 deletion docs/api/power-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Monitor power state changes.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

## Events

Expand Down
2 changes: 1 addition & 1 deletion docs/api/power-save-blocker.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Block the system from entering low-power (sleep) mode.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

For example:

Expand Down
2 changes: 1 addition & 1 deletion docs/api/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Register a custom protocol and intercept existing protocol requests.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

An example of implementing a protocol that has the same effect as the
`file://` protocol:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/screen.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Retrieve information about screen size, displays, cursor position, etc.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

This module cannot be used until the `ready` event of the `app`
module is emitted.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Manage browser sessions, cookies, cache, proxy settings, etc.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

The `session` module can be used to create new `Session` objects.

Expand Down
2 changes: 1 addition & 1 deletion docs/api/share-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Create share menu on macOS.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

The `ShareMenu` class creates [Share Menu][share-menu] on macOS, which can be
used to share information from the current context to apps, social media
Expand Down
2 changes: 1 addition & 1 deletion docs/api/shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Manage files and URLs using their default applications.
Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process) (non-sandboxed only)
Exported in: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer-process) (non-sandboxed only)

The `shell` module provides functions related to desktop integration.

Expand Down
2 changes: 1 addition & 1 deletion docs/api/system-preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Get system preferences.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

```javascript
const { systemPreferences } = require('electron')
Expand Down
2 changes: 1 addition & 1 deletion docs/api/touch-bar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Create TouchBar layouts for native macOS applications
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

### `new TouchBar(options)`

Expand Down
2 changes: 1 addition & 1 deletion docs/api/tray.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Add icons and context menus to the system's notification area.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

`Tray` is an [EventEmitter][event-emitter].

Expand Down
2 changes: 1 addition & 1 deletion docs/api/web-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Render and control web pages.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

`webContents` is an [EventEmitter][event-emitter].
It is responsible for rendering and controlling a web page and is a property of
Expand Down
2 changes: 1 addition & 1 deletion docs/api/web-frame-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Control web pages and iframes.
Process: [Main](../glossary.md#main-process)
Exported in: [Main](../glossary.md#main-process)

The `webFrameMain` module can be used to lookup frames across existing
[`WebContents`](web-contents.md) instances. Navigation events are the common
Expand Down
2 changes: 1 addition & 1 deletion docs/api/web-frame.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Customize the rendering of the current web page.
Process: [Renderer](../glossary.md#renderer-process)
Exported in: [Renderer](../glossary.md#renderer-process)

`webFrame` export of the Electron module is an instance of the `WebFrame`
class representing the top frame of the current `BrowserWindow`. Sub-frames can
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"repository": "https://github.com/electron/electron",
"description": "Build cross platform desktop apps with JavaScript, HTML, and CSS",
"devDependencies": {
"@electron/docs-parser": "^0.11.0",
"@electron/typescript-definitions": "^8.9.0",
"@electron/docs-parser": "^0.12.0",
"@electron/typescript-definitions": "^8.9.2",
"@octokit/auth-app": "^2.10.0",
"@octokit/rest": "^18.0.3",
"@primer/octicons": "^10.0.0",
Expand Down
16 changes: 8 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

"@electron/docs-parser@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@electron/docs-parser/-/docs-parser-0.11.0.tgz#182a9732d2fc7b40e3f506d3ab1a06270cdae6e4"
integrity sha512-i+OSWXXchoKVorR6cANqPKYJ1ccLAp+YCPTB+IJVWZ+Xtp6V2VXqLsjoy4mD32ss4CdX/6MLX62pb2sjGmmR6w==
"@electron/docs-parser@^0.12.0":
version "0.12.0"
resolved "https://registry.yarnpkg.com/@electron/docs-parser/-/docs-parser-0.12.0.tgz#a1ae37164bf93f9cabcb1d51f19146a0a7f07168"
integrity sha512-/z9XUi5z752tpNa+fC+STtGKKOT9lQ9PgU15MMSUtOHRVbNfoQfGoFQaiUKi5uqH+UnAwBZ+p8PHId30KtVxCA==
dependencies:
"@types/markdown-it" "^10.0.0"
chai "^4.2.0"
Expand All @@ -33,10 +33,10 @@
ora "^4.0.3"
pretty-ms "^5.1.0"

"@electron/typescript-definitions@^8.9.0":
version "8.9.0"
resolved "https://registry.yarnpkg.com/@electron/typescript-definitions/-/typescript-definitions-8.9.0.tgz#4a446ef875b55f6d3736df2a33bb19257b8146aa"
integrity sha512-26ze33/Ip2ivpCMHGRMLR+Dcm7DLNzPJL0iLJNonqPu2ikqnwJce1d2vkTDBBLzAiqUV3litVNTpnNS2Zg42MA==
"@electron/typescript-definitions@^8.9.2":
version "8.9.2"
resolved "https://registry.yarnpkg.com/@electron/typescript-definitions/-/typescript-definitions-8.9.2.tgz#a68d01cd76a87d3aa81baa4ba2641c9445118181"
integrity sha512-govyGHx1TUwwJvGVr/LT8QRMI4m/1cg/lEGObcIAhEcYTrPFDrDm3dUJmMOQKbaJuthY+WJcB8O5TFwoKIFMpQ==
dependencies:
"@types/node" "^11.13.7"
chalk "^2.4.2"
Expand Down

0 comments on commit 384966e

Please sign in to comment.