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 types for electron-positioner #57354

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 61 additions & 0 deletions types/electron-positioner/electron-positioner-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import Positioner = require("electron-positioner");
import { BrowserWindow } from 'electron';

const positioner = new Positioner(new BrowserWindow());
const rectangle: Electron.Rectangle = { x: 0, y: 0, width: 0, height: 0 };

// $ExpectError
positioner.move('trayLeft');

// $ExpectType void
positioner.move('trayLeft', rectangle);

// $ExpectType void
positioner.move('topLeft');

// $ExpectType void
positioner.move('topLeft', rectangle);

// $ExpectError
positioner.calculate('trayLeft');

// $ExpectType { x: number; y: number; }
positioner.calculate('trayLeft', rectangle);

// $ExpectType { x: number; y: number; }
positioner.calculate('topLeft');

// $ExpectType { x: number; y: number; }
positioner.calculate('topLeft', rectangle);

positioner.move('trayLeft', rectangle);
positioner.move('trayBottomLeft', rectangle);
positioner.move('trayRight', rectangle);
positioner.move('trayBottomRight', rectangle);
positioner.move('trayCenter', rectangle);
positioner.move('trayBottomCenter', rectangle);
positioner.move('topLeft');
positioner.move('topRight');
positioner.move('bottomLeft');
positioner.move('bottomRight');
positioner.move('topCenter');
positioner.move('bottomCenter');
positioner.move('leftCenter');
positioner.move('rightCenter');
positioner.move('center');

positioner.calculate('trayLeft', rectangle);
positioner.calculate('trayBottomLeft', rectangle);
positioner.calculate('trayRight', rectangle);
positioner.calculate('trayBottomRight', rectangle);
positioner.calculate('trayCenter', rectangle);
positioner.calculate('trayBottomCenter', rectangle);
positioner.calculate('topLeft');
positioner.calculate('topRight');
positioner.calculate('bottomLeft');
positioner.calculate('bottomRight');
positioner.calculate('topCenter');
positioner.calculate('bottomCenter');
positioner.calculate('leftCenter');
positioner.calculate('rightCenter');
positioner.calculate('center');
39 changes: 39 additions & 0 deletions types/electron-positioner/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Type definitions for electron-positioner 4.1
// Project: https://github.com/jenslind/electron-positioner
// Definitions by: ktmouk <https://github.com/ktmouk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import { BrowserWindow, Rectangle } from 'electron';

declare namespace ElectronPositioner {
type Position =
| 'topLeft'
| 'topRight'
| 'bottomLeft'
| 'bottomRight'
| 'topCenter'
| 'bottomCenter'
| 'leftCenter'
| 'rightCenter'
| 'center';

type TrayPosition =
| 'trayLeft'
| 'trayBottomLeft'
| 'trayRight'
| 'trayBottomRight'
| 'trayCenter'
| 'trayBottomCenter';
}

declare class ElectronPositioner {
constructor(browserWindow: BrowserWindow);

move(position: ElectronPositioner.Position, trayBounds?: Rectangle): void;
move(position: ElectronPositioner.TrayPosition, trayBounds: Rectangle): void;

calculate(position: ElectronPositioner.Position, trayBounds?: Rectangle): { x: number; y: number };
calculate(position: ElectronPositioner.TrayPosition, trayBounds: Rectangle): { x: number; y: number };
}

export = ElectronPositioner;
6 changes: 6 additions & 0 deletions types/electron-positioner/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"electron": "^15.3.1"
}
}
24 changes: 24 additions & 0 deletions types/electron-positioner/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"electron-positioner-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/electron-positioner/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }