plugin: add type assertions for strictNullChecks in runtime workers

Fix strictNullChecks:
- child-process-worker.ts: add definite assignment for childProcess
- custom-worker.ts: add assertions for pluginDevice and options
- node-fork-worker.ts: add catch block type annotation
- node-thread-worker.ts: add catch block type annotation
- python-worker.ts: add assertions for worker properties
This commit is contained in:
Koushik Dutta
2026-04-02 14:57:53 -07:00
parent 2bd8354ead
commit 5a1c3d024b
5 changed files with 9 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ import { RuntimeWorker, RuntimeWorkerOptions } from "./runtime-worker";
export abstract class ChildProcessWorker extends EventEmitter implements RuntimeWorker {
public pluginId: string;
protected worker: child_process.ChildProcess | undefined;
killPromise: Promise<void>;
killPromise!: Promise<void>;
get childProcess() {
return this.worker;

View File

@@ -8,13 +8,13 @@ import { ChildProcessWorker } from "./child-process-worker";
import { RuntimeWorkerOptions } from "./runtime-worker";
export class CustomRuntimeWorker extends ChildProcessWorker {
serializer: ReturnType<typeof createRpcDuplexSerializer>;
fork: boolean;
serializer!: ReturnType<typeof createRpcDuplexSerializer>;
fork!: boolean;
constructor(options: RuntimeWorkerOptions, runtime: ScryptedRuntime) {
super(options);
const pluginDevice = runtime.findPluginDevice(this.pluginId);
const pluginDevice = runtime.findPluginDevice(this.pluginId)!;
const scryptedRuntimeArguments: ScryptedRuntimeArguments = pluginDevice.state.scryptedRuntimeArguments?.value;
if (!scryptedRuntimeArguments)
throw new Error('custom runtime requires scryptedRuntimeArguments');
@@ -75,7 +75,7 @@ export class CustomRuntimeWorker extends ChildProcessWorker {
this.serializer.sendMessage(message, reject, serializationContext);
}
catch (e) {
reject?.(e);
reject?.(e as Error);
}
}
}

View File

@@ -105,7 +105,7 @@ export class NodeForkWorker extends ChildProcessWorker {
});
}
catch (e) {
reject?.(e);
reject?.(e as Error);
}
}

View File

@@ -129,7 +129,7 @@ export class NodeThreadWorker extends EventEmitter implements RuntimeWorker {
port.postMessage(postMessage, transferList);
}
catch (e) {
reject?.(e);
reject?.(e as Error);
}
}

View File

@@ -26,7 +26,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
}
}
serializer: ReturnType<typeof createRpcDuplexSerializer>;
serializer!: ReturnType<typeof createRpcDuplexSerializer>;
peerin: Writable;
peerout: Readable;
_stdout = new PassThrough();
@@ -200,7 +200,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
this.serializer.sendMessage(message, reject, serializationContext);
}
catch (e) {
reject?.(e);
reject?.(e as Error);
}
}
}