Skip to content

Commit

Permalink
feat: add lib.worker.d.ts (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain authored Jan 15, 2024
1 parent 6bb3730 commit 5f642ef
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/global/types/lib.worker.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface MiniProgramWorker {
onMessage<T = Record<string, unknown>>(cb: (message: T) => void): void;
postMessage<T = Record<string, unknown>>(message: T): void;
/**
* 用于模拟 iOS ExperimentalWorker 线程被系统回收事件,主线程中通过 Worker.onProcessKilled 监听, 以便于调试。
* 仅限 iOS 系统, 仅支持在 worker 线程内可用。
*/
testOnProcessKilled(): void;
}

declare var worker: MiniProgramWorker;
8 changes: 8 additions & 0 deletions tests/global/worker.test.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 5f642ef

Please sign in to comment.