Fix ts errors in lib/utils

This commit is contained in:
Labhansh Agrawal 2019-10-12 15:46:45 +05:30 committed by Benjamin Staneck
parent 187897a1f0
commit d2a318d48b
7 changed files with 25 additions and 18 deletions

View file

@ -1,12 +1,12 @@
import {ipcRenderer, remote} from 'electron';
const plugins = remote.require('./plugins');
const plugins = remote.require('./plugins') as typeof import('../../app/plugins');
export function getConfig() {
return plugins.getDecoratedConfig();
}
export function subscribe(fn) {
export function subscribe(fn: (event: Electron.IpcRendererEvent, ...args: any[]) => void) {
ipcRenderer.on('config change', fn);
ipcRenderer.on('plugins change', fn);
return () => {

View file

@ -7,7 +7,7 @@
* as the result of an action being triggered.
*/
export default () => next => action => {
export default () => (next: (arg0: any) => any) => (action: {effect: () => void}) => {
const ret = next(action);
if (action.effect) {
action.effect();

View file

@ -1,5 +1,5 @@
/* eslint no-new:0 */
export default function notify(title, body, details = {}) {
export default function notify(title: string, body: string, details: Record<string, any> = {}) {
//eslint-disable-next-line no-console
console.log(`[Notification] ${title}: ${body}`);
if (details.error) {

View file

@ -1,6 +1,6 @@
const valsCache = new WeakMap();
export function values(imm) {
export function values(imm: Record<string, any>) {
if (!valsCache.has(imm)) {
valsCache.set(imm, Object.values(imm));
}
@ -8,7 +8,7 @@ export function values(imm) {
}
const keysCache = new WeakMap();
export function keys(imm) {
export function keys(imm: Record<string, any>) {
if (!keysCache.has(imm)) {
keysCache.set(imm, Object.keys(imm));
}

View file

@ -1,12 +1,12 @@
import {clipboard} from 'electron';
import plist from 'plist';
const getPath = platform => {
const getPath = (platform: string) => {
switch (platform) {
case 'darwin': {
if (clipboard.has('NSFilenamesPboardType')) {
// Parse plist file containing the path list of copied files
const list = plist.parse(clipboard.read('NSFilenamesPboardType'));
const list = plist.parse(clipboard.read('NSFilenamesPboardType')) as plist.PlistArray;
return "'" + list.join("' '") + "'";
} else {
return null;

View file

@ -1,7 +1,11 @@
import {EventEmitter} from 'events';
import {IpcRenderer, IpcRendererEvent} from 'electron';
import electron from 'electron';
export default class Client {
emitter: EventEmitter;
ipc: IpcRenderer;
id!: string;
constructor() {
const electron = window.require('electron');
const EventEmitter = window.require('events');
this.emitter = new EventEmitter();
this.ipc = electron.ipcRenderer;
this.ipcListener = this.ipcListener.bind(this);
@ -12,7 +16,7 @@ export default class Client {
this.emitter.emit('ready');
}, 0);
} else {
this.ipc.on('init', (ev, uid) => {
this.ipc.on('init', (ev: IpcRendererEvent, uid: string) => {
// we cache so that if the object
// gets re-instantiated we don't
// wait for a `init` event
@ -24,26 +28,26 @@ export default class Client {
}
}
ipcListener(event, {ch, data}) {
ipcListener(event: any, {ch, data}: {ch: string; data: any}) {
this.emitter.emit(ch, data);
}
on(ev, fn) {
on(ev: string, fn: (...args: any[]) => void) {
this.emitter.on(ev, fn);
}
once(ev, fn) {
once(ev: string, fn: (...args: any[]) => void) {
this.emitter.once(ev, fn);
}
emit(ev, data) {
emit(ev: string, data: any) {
if (!this.id) {
throw new Error('Not ready');
}
this.ipc.send(this.id, {ev, data});
}
removeListener(ev, fn) {
removeListener(ev: string, fn: (...args: any[]) => void) {
this.emitter.removeListener(ev, fn);
}
@ -53,6 +57,6 @@ export default class Client {
destroy() {
this.removeAllListeners();
this.ipc.removeAllListeners();
this.ipc.removeAllListeners(this.id);
}
}

View file

@ -1,4 +1,7 @@
export default function findBySession(termGroupState, sessionUid) {
import {ITermState} from '../hyper';
import {Immutable} from 'seamless-immutable';
export default function findBySession(termGroupState: Immutable<ITermState>, sessionUid: string) {
const {termGroups} = termGroupState;
return Object.keys(termGroups)
.map(uid => termGroups[uid])