Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TypeScript definition #68

Merged
merged 7 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export interface Options {
/**
* Default: [Only in development](https://github.com/sindresorhus/electron-is-dev)
*/
enabled?: boolean;

/**
* Show DevTools on each created `BrowserWindow`.
*
* @default true
*/
showDevTools?: boolean;

/**
* The dock state to open DevTools in.
*
* @default 'undocked'
*/
devToolsMode?: 'undocked' | 'right' | 'bottom' | 'previous' | 'detach';
}

/**
* Install keyboard shortcuts and optionally activate DevTools on each created `BrowserWindow`.
*
* @example
*
* import {app, BrowserWindow} from 'electron';
* import electronDebug from 'electron-debug';
*
* electronDebug();
*
* let win;
* (async () => {
* await app.whenReady();
* win = new BrowserWindow();
* });
*/
export default function electronDebug(options?: Options): void;

/**
* Reload the specified `BrowserWindow` instance or the focused one.
*
* @param window - Default: BrowserWindow.getFocusedWindow()
*/
export function refresh(window?: Electron.BrowserWindow): void;
Copy link
Owner

@sindresorhus sindresorhus Jan 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you use a default parameter here?

export function refresh(window?: Electron.BrowserWindow = BrowserWindow.getFocusedWindow()): void;

Then line 43 would be moot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the default value doesn't seem to show up in the inline docs preview when using this syntax.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it’s valid syntax, right? If so, I think we should still use it and open an issue on VSCode about it.


/**
* Toggle DevTools for the specified `BrowserWindow` instance or the focused one.
*
* @param window - Default: BrowserWindow.getFocusedWindow()
*/
export function devTools(window?: Electron.BrowserWindow): void;

/**
* Open DevTools for the specified `BrowserWindow` instance or the focused one.
*
* @param window - Default: BrowserWindow.getFocusedWindow()
*/
export function openDevTools(window?: Electron.BrowserWindow): void;
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ module.exports = opts => {
});
};

module.exports.default = module.exports;

module.exports.refresh = refresh;
module.exports.devTools = devTools;
module.exports.openDevTools = openDevTools;
12 changes: 12 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {expectType} from 'tsd-check';
import {BrowserWindow} from 'electron';
import electronDebug, {refresh, devTools, openDevTools} from '.';

expectType<void>(electronDebug({
enabled: true,
showDevTools: true
}));

expectType<void>(refresh(new BrowserWindow()));
expectType<void>(devTools());
expectType<void>(openDevTools());
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
},
"scripts": {
"start": "electron test.js",
"test": "xo"
"test": "xo && tsd-check"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],
"keywords": [
"electron",
Expand All @@ -33,6 +34,7 @@
"devtron": "^1.1.0",
"electron": "^2.0.2",
"electron-react-devtools": "^0.5.3",
"tsd-check": "^0.3.0",
"xo": "*"
},
"xo": {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Show DevTools on each created `BrowserWindow`.

Type: `string`<br>
Default: `undocked`<br>
Values: `undocked` `right` `bottom` `previous`
Values: `undocked` `right` `bottom` `previous` `detach`

The dock state to open DevTools in.

Expand Down