diff --git a/lib/worker.ts b/lib/worker.ts index 3af09685..98f8515a 100644 --- a/lib/worker.ts +++ b/lib/worker.ts @@ -10,6 +10,7 @@ import type { ConfigSchema } from "./config" import type { emit } from 'node:cluster'; import type * as Tslint from "tslint"; import type * as Ts from "typescript"; +import type { JobMessage, ConfigMessage } from "./workerHelper" process.title = 'linter-tslint worker'; @@ -258,7 +259,7 @@ export default async function TsLintWorker(initialConfig: ConfigSchema) { config.useGlobalTslint = initialConfig.useGlobalTslint; config.globalNodePath = initialConfig.globalNodePath; - process.on('message', async (message) => { + process.on('message', async (message: JobMessage | ConfigMessage) => { if (message.messageType === 'config') { config[message.message.key] = message.message.value; diff --git a/lib/workerHelper.ts b/lib/workerHelper.ts index 2c476c9c..0240756f 100644 --- a/lib/workerHelper.ts +++ b/lib/workerHelper.ts @@ -1,4 +1,4 @@ -import { Task } from 'atom'; +import { Task, TextEditor } from 'atom'; import type { ConfigSchema } from "./config" import cryptoRandomString from 'crypto-random-string'; @@ -26,16 +26,16 @@ export default class WorkerHelper { } } - changeConfig(key, value) { + changeConfig(key: string, value: any) { if (this.workerInstance) { this.workerInstance.send({ messageType: 'config', message: { key, value }, - }); + } as ConfigMessage); } } - requestJob(jobType, textEditor) { + requestJob(jobType: string, textEditor: TextEditor) { if (!this.workerInstance) { throw new Error("Worker hasn't started"); } @@ -66,10 +66,28 @@ export default class WorkerHelper { content: textEditor.getText(), filePath: textEditor.getPath(), }, - }); + } as JobMessage); } catch (e) { reject(e); } }); } } + +export type ConfigMessage = { + messageType: 'config', + message: { + key: string, + value: any, + } +} + +export type JobMessage = { + messageType: 'job', + message: { + emitKey: string, + jobType: string, + content: ReturnType, + filePath: ReturnType, + } +}