diff --git a/lib/utils/config.ts b/lib/utils/config.ts index b8b547f4..7c709eac 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -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 () => { diff --git a/lib/utils/effects.ts b/lib/utils/effects.ts index db1cc61b..88b2b7a3 100644 --- a/lib/utils/effects.ts +++ b/lib/utils/effects.ts @@ -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(); diff --git a/lib/utils/notify.ts b/lib/utils/notify.ts index 7e87c1d2..1e313ee0 100644 --- a/lib/utils/notify.ts +++ b/lib/utils/notify.ts @@ -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 = {}) { //eslint-disable-next-line no-console console.log(`[Notification] ${title}: ${body}`); if (details.error) { diff --git a/lib/utils/object.ts b/lib/utils/object.ts index 10f5d238..08f9335f 100644 --- a/lib/utils/object.ts +++ b/lib/utils/object.ts @@ -1,6 +1,6 @@ const valsCache = new WeakMap(); -export function values(imm) { +export function values(imm: Record) { 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) { if (!keysCache.has(imm)) { keysCache.set(imm, Object.keys(imm)); } diff --git a/lib/utils/paste.ts b/lib/utils/paste.ts index a77b15ab..51120943 100644 --- a/lib/utils/paste.ts +++ b/lib/utils/paste.ts @@ -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; diff --git a/lib/utils/rpc.ts b/lib/utils/rpc.ts index 3fdfe4ab..dbdfa860 100644 --- a/lib/utils/rpc.ts +++ b/lib/utils/rpc.ts @@ -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); } } diff --git a/lib/utils/term-groups.ts b/lib/utils/term-groups.ts index 4b8c6bd6..f012f5ea 100644 --- a/lib/utils/term-groups.ts +++ b/lib/utils/term-groups.ts @@ -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, sessionUid: string) { const {termGroups} = termGroupState; return Object.keys(termGroups) .map(uid => termGroups[uid])