diff --git a/packages/global/types/lib.worker.d.ts b/packages/global/types/lib.worker.d.ts new file mode 100644 index 0000000..46d4bff --- /dev/null +++ b/packages/global/types/lib.worker.d.ts @@ -0,0 +1,11 @@ +export interface MiniProgramWorker { + onMessage>(cb: (message: T) => void): void; + postMessage>(message: T): void; + /** + * 用于模拟 iOS ExperimentalWorker 线程被系统回收事件,主线程中通过 Worker.onProcessKilled 监听, 以便于调试。 + * 仅限 iOS 系统, 仅支持在 worker 线程内可用。 + */ + testOnProcessKilled(): void; +} + +declare var worker: MiniProgramWorker; diff --git a/tests/global/worker.test.ts b/tests/global/worker.test.ts new file mode 100644 index 0000000..72d50a3 --- /dev/null +++ b/tests/global/worker.test.ts @@ -0,0 +1,8 @@ +import type { MiniProgramWorker } from '../../packages/global/types/lib.worker'; +import { expectAssignable } from 'tsd-lite'; + +declare const worker: MiniProgramWorker; + +expectAssignable<(cb: (evt: any) => any) => any>(worker.onMessage); +expectAssignable<(message: any) => any>(worker.postMessage); +expectAssignable<() => any>(worker.testOnProcessKilled);