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 4 commits
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
61 changes: 61 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { BrowserWindow } from "electron";

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?: Readonly<Options>): void;
Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I think we should use readonly on the specific properties whenever possible, as Readonly will show up in the code completion and create noise: screen shot 2019-01-28 at 19 56 25

Maybe that's a non-issue. I dunno.

Thoughts?


*Really want the readonly type operators...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure either…
Is that information useful in any way to the end user of the API? If it's not, then sure, readonly all the props. 😉

Copy link
Owner

Choose a reason for hiding this comment

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

It’s not. It’s only useful for us to ensure we don’t modify the object.

Copy link
Owner

Choose a reason for hiding this comment

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

Let’s go with per-property annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

*Really want the readonly type operators...

Btw. TS seems to be slowly closing in on that… 😅
microsoft/TypeScript#29435
microsoft/TypeScript#29510

Not quite there yet, but I like the trajectory. 😉


/**
* Reload the specified `BrowserWindow` instance or the focused one.
*
* @param [window]
CvX marked this conversation as resolved.
Show resolved Hide resolved
*/
export function refresh(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): void;

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

/**
* Open DevTools for the specified `BrowserWindow` instance or the focused one.
*
* @param [window]
*/
export function openDevTools(window?: BrowserWindow = BrowserWindow.getFocusedWindow()): 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