Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add lib.worker.d.ts #41

Merged
merged 3 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading